Answer the question
In order to leave comments, you need to log in
How to use condition in webpack config?
Hello. I'm trying to use the cross-env module to only run the purgecss plugin on production builds. Found such a solution;
Here is the command with cross-env
"scripts": {
"start": "cross-env NODE_ENV=development webpack serve --config webpack/webpack.config.babel.js --mode development"
}
const isDev = process.env.NODE_ENV === 'development';
const isProd = !isDev;
if (isProd) {
// Используем PurgeCSS.
}
Answer the question
In order to leave comments, you need to log in
And in webpack.config.js you need to write this
The webpack config is a regular js file. Can you write in js?
const config = {
entry: './src/index.js',
output: {
// ...
},
module: {
// ...
},
plugins: [
new MiniCssExtractPlugin({
filename: 'assets/css/style.css'
}),
// ...
]
};
if (isDev) {
config.plugins.push( new PurgecssPlugin() );
}
module.exports = config;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question