Skip to content

docs(README): add autoprefixing example #380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 27 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ module.exports = ({ file, options, env }) => ({
parser: file.extname === '.sss' ? 'sugarss' : false,
plugins: {
'postcss-import': { root: file.dirname },
'postcss-preset-env': options.presetEnv ? options.presetEnv : false,
'postcss-preset-env': options['postcss-preset-env'] ? options['postcss-preset-env'] : false,
'cssnano': env === 'production' ? options.cssnano : false
}
})
Expand All @@ -192,9 +192,8 @@ module.exports = ({ file, options, env }) => ({
options: {
config: {
ctx: {
cssnext: {...options},
'postcss-preset-env': {...options},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using 'postcss-preset-env' as the key here conflicts with the usage in the config file (options.presetEnv) above, one would have to access it via bracket notation options['postcss-preset-env'] instead of dot notation (options.presetEnv) as currently used. Either rename the key in webpack.config.js or use bracket notation in postcss.confg.js aswell :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks for the feedback! I have addressed it by renaming the options.presetEnv -> options['postcss-preset-env']

cssnano: {...options},
autoprefixer: {...options}
}
}
}
Expand All @@ -212,7 +211,6 @@ module.exports = ({ file, options, env }) => ({
plugins: (loader) => [
require('postcss-import')({ root: loader.resourcePath }),
require('postcss-preset-env')(),
require('autoprefixer')(),
require('cssnano')()
]
}
Expand Down Expand Up @@ -332,6 +330,31 @@ within the CSS directly as an annotation comment.
}
```

### Autoprefixing

**webpack.config.js**
```js
{
test: /\.css$/,
use: [
'style-loader',
'css-loader',
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: [
require('autoprefixer')({...options}),
...,
]
}
}
]
}
```

> :warning: [`postcss-preset-env`](https://github.com/csstools/postcss-preset-env) includes [`autoprefixer`](https://github.com/postcss/autoprefixer), so adding it separately is not necessary if you already use the preset.

### `CSS Modules`

This loader [cannot be used] with [CSS Modules] out of the box due
Expand Down