Last active
May 26, 2019 16:20
-
-
Save richardkall/910d6b9786bea5a8918ebf38e4921892 to your computer and use it in GitHub Desktop.
Webpack CSS loaders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); | |
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'); | |
module.exports = (env = { production: false }) => ({ | |
module: { | |
rules: [ | |
{ | |
test: /\.css$/, | |
use: [ | |
...(env.production | |
? [{ loader: MiniCssExtractPlugin.loader }] | |
: ['style-loader']), | |
{ | |
loader: 'css-loader', | |
options: { | |
importLoaders: 1, | |
localIdentName: env.production | |
? '[hash:base64:8]' | |
: '[name]__[local]', | |
modules: true, | |
sourceMap: !env.production, | |
}, | |
}, | |
{ | |
loader: 'postcss-loader', | |
options: { | |
ident: 'postcss', | |
plugins: () => [ | |
require('postcss-preset-env')({ | |
features: { | |
'custom-media-queries': true, | |
'nesting-rules': true, | |
}, | |
importFrom: path.resolve( | |
__dirname, | |
'src/styles/variables.css', | |
), | |
preserve: false, | |
}), | |
], | |
sourceMap: !env.production, | |
}, | |
}, | |
], | |
} | |
], | |
}, | |
plugins: [ | |
...(env.production | |
? [ | |
new MiniCssExtractPlugin({ | |
filename: env.production | |
? '[name].[chunkhash:8].css' | |
: '[name].css', | |
}), | |
new OptimizeCssAssetsPlugin(), | |
] | |
: []), | |
], | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment