Skip to content

Commit

Permalink
Merge pull request #51 from kimroen/sn/add-project-targets
Browse files Browse the repository at this point in the history
Pass through config/targets to autoprefixer
  • Loading branch information
snewcomer committed May 26, 2020
2 parents da7cd31 + a813bf6 commit f8b9957
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Expand Up @@ -10,12 +10,14 @@ ember install ember-cli-autoprefixer
```

## Options
Add the target browsers to your package.json as per https://github.com/browserslist/browserslist#readme or use a `.browserslistrc` file.
This addon first consumes your browser list config from `config/targets.js`. This is the browser list for Babel.

You can manually configure what browsers to target and other options by
specifying them in your `ember-cli-build.js` (or `Brocfile.js`). An example:
You can manually configure what browsers to target for autoprefixer only. Add the target browsers to your package.json
as per https://github.com/browserslist/browserslist#readme, add a `.browserslistrc` file, or configure `overrideBrowsersList`
in `ember-cli-build.js`.

```js
// ember-cli-build.js
var app = new EmberApp(defaults, {
autoprefixer: {
overrideBrowserslist: ['IE11'],
Expand Down
13 changes: 13 additions & 0 deletions index.js
@@ -1,6 +1,7 @@
'use strict';

const Autoprefixer = require('broccoli-autoprefixer');
const fs = require('fs');

const treesToProcess = ['css', 'less', 'styl', 'scss', 'sass'];

Expand All @@ -15,10 +16,22 @@ module.exports = {

this._super.included.apply(this, arguments);

var browserOptions = {};

var root = this.project.root;
var hasRCFile = fs.existsSync(`${root}/.browserslistrc`);
var hasPkgBrowserList = !!this.project.pkg.browserslist;

if (!hasRCFile && !hasPkgBrowserList) {
var appOptions = this.app.options || {};
browserOptions.overrideBrowsersList = appOptions['autoprefixer'] && appOptions['autoprefixer'].overrideBrowsersList;
}

this.options = Object.assign(
{
enabled: true
},
browserOptions,
this.app.options.autoprefixer || {}
);

Expand Down

0 comments on commit f8b9957

Please sign in to comment.