Giter Club home page Giter Club logo

ember-cli-postcss's Introduction

ember-cli-postcss

Build Status npm version Ember Observer Score

Use postcss to process your css with a large selection of plug-ins.

Installation

ember install ember-cli-postcss

Usage

The add-on can be used in two ways:

  • on individual files, referred to as “compile”
  • on all CSS files, referred to as “filter”

Note: it’s possible to use both compile and filter.

Compile

This step will look for either app.css or <project-name>.css in your styles directory. Additional files to be processed can be defined in the output paths configuration object for your application:

const app = new EmberApp(defaults, {
  outputPaths: {
    app: {
      html: 'index.html',
      css: {
        'app': '/assets/app.css',
        'print': '/assets/print.css'
      }
    }
  }
}

Filter

This step will run at the end of the build process on all CSS files, including the merged vendor.css file and any CSS imported into the Broccoli tree by add-ons.

Files can be white-listed and/or black-listed by using the respective include and exclude options. Each accepts an array of file globs, which are then passed on to Broccoli Funnel. An example can be seen in the sample configuration below.

Configuring Plug-ins

There are two steps to setting up postcss with ember-cli-postcss:

  1. install and require the node modules for any plug-ins
  2. provide the node module and plug-in options as a postcssOptions object in ember-cli-build.js

The postcssOptions object should have a “compile” and/or “filter” property, which will have the properties enabled and plugins, which is an array of objects that contain a module property and an options property:

Browser Targets

Some postcss plug-ins, like autoprefixer, allow you to configure which browsers to target for transpilation. When using Ember CLI >= 2.13.0, the browser targets configuration found in the file config/targets.js will be added to each plug-in’s options (as options.browsers). This browser list can be overwritten on a plug-in by plug-in basis. You can learn more about the targets feature on the Ember.js blog.

postcssOptions: {
  compile: {
    enabled: true, // defaults to true
    browsers: ['last 3 versions'], // this will override config found in config/targets.js
    plugins: [
      {
        module: <module>,
        options: {
          ...
        }
      }
    ]
  },
  filter: {
    enabled: true, // defaults to false
    map: false, // defaults to inline, false in production
    browsers: ['last 3 versions'], // this will override config found in config/targets.js
    include: ['styles/*.css'],
    exclude: ['vendor/bootstrap/**/*'],
    plugins: [
      {
        module: <module>,
        options: {
          ...
        }
      }
    ]
  }
}

Example

Install the autoprefixer plug-in:

npm i --save-dev autoprefixer

Specify some plug-ins in your ember-cli-build.js:

const EmberApp = require('ember-cli/lib/broccoli/ember-app');
const autoprefixer = require('autoprefixer');

module.exports = function (defaults) {
  const app = new EmberApp(defaults, {
    postcssOptions: {
      compile: {
        enabled: false,
        browsers: ['last 3 versions'], // this will override config found in config/targets.js
      },
      filter: {
        enabled: true,
        plugins: [
          {
            module: autoprefixer,
            options: {
              browsers: ['last 2 versions'] // this will override the config, but just for this plugin
            }
          }
        ]
      }
    }
  });
  return app.toTree();
};

ember-cli-postcss's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.