How to use autoprefixer
with webpack 2.x.
Previously, it used to be something like this...
... module: { loaders: [ { test: /\.scss$/, loader: 'style!css!sass!postcss' } ] }, postcss: () => { return [autoprefixer] }, ...
But, it's not working anymore.
How to rewrite it to [email protected]?
For Webpack v4, you have to install postcss-loader v4. Then add the plugin to your webpack config. For example: In the following configuration the plugin postcss-preset-env is used, which is not installed by default.
PostCSS is: a tool for transforming styles with JS plugins. These plugins can lint your CSS, support variables and mixins, transpile future CSS syntax, inline images, and more.
PostCSS is a JavaScript tool that transforms your CSS code into an abstract syntax tree (AST) and then provides an API (application programming interface) for analyzing and modifying it using JavaScript plugins.
There is no more need to use LoaderOptionsPlugin
. Now you can pass options directly to the loader declaration.
const autoprefixer = require('autoprefixer'); let settings = { /*...*/ module: { rules: [{ test: /\.css$/, use: [ /*...other loaders...*/ { loader: 'postcss-loader', options: { plugins: function () { return [autoprefixer] } } } /*...other loaders...*/ ] }]} } /*...*/ };
In case if you need to provide specific compatibility configuration, you can pass it as argument to autoprefixer
function:
options: { plugins: function () { return [autoprefixer('last 2 versions', 'ie 10')] } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With