I am currently using css module with miniCssExtractPlugin, it is wired it is not working,it do extract css into a separate css file, but the css file is empty.when i use style-loader it looks good with css module, but it will not extract css to a separate file.
const cssDevRules=[
{
loader:'style-loader'
},
{
loader:'css-loader?modules&localIdentName=[name]_[local]_[hash:base64:5]',
},
{
loader:'sass-loader',
}];
but when i try to use miniCssExtractPlugin in production mode, the generate css file is empty.code as below:
const cssProdRules=[
{
loader: MiniCssExtractPlugin.loader,
},
{
loader:'css-loader?modules&localIdentName=[name]_[local]_[hash:base64:5]',
},
{
loader:'sass-loader',
}];
i also try to use style-loader with ExtractTextPlugin, still not working, anyone can tell me how to fix this up? i will put all my webpack.config.json here for your reference.
const path = require('path');
const glob = require("glob");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const PurifyCSSPlugin = require("purifycss-webpack");
const isProd = process.env.NODE_ENV === 'production';
const PATHS = {
app: path.join(__dirname, "src"),
};
const MiniCssPlugin = new MiniCssExtractPlugin({
filename: "[name].css",
});
const PurifyCssPlugin = new PurifyCSSPlugin({
paths: glob.sync(`${PATHS.app}/**/*.js`, { nodir: true }),
});
const cssDevRules=[
{
loader:'style-loader'
},
{
loader:'css-loader?modules&localIdentName=[name]_[local]_[hash:base64:5]',
},
{
loader:'sass-loader',
}
];
const cssProdRules=[
{
loader: MiniCssExtractPlugin.loader,
// loader:'style-loader'
},
{
loader:'css-loader?modules&localIdentName=[name]_[local]_[hash:base64:5]',
},
{
loader:'sass-loader',
}
];
console.log("is prod:"+isProd);
const baseConfig = {
module: {
rules: [
{
test: /\.(css|sass|scss)$/,
use: isProd? cssProdRules:cssDevRules,
exclude: /node_modules/,
},
]
},
};
if(isProd){
baseConfig.plugins=[
MiniCssPlugin,
PurifyCssPlugin,
];
}
module.exports = baseConfig;
the production mode is not working , the css generate by MiniCssExtract is empty, anyone can help on this?