P粉8845486192023-08-26 09:13:35
You can use MiniCssExtractPlugin to perform CSS tree shaking. If you are using scss or sass, you can add these loaders as well.
// webpack.config.js (production) const path = require('path') const MiniCssExtractPlugin = require('mini-css-extract-plugin') module.exports = { mode: 'production', entry: path.resolve('src/index.js'), output: { filename: '[name].js', path: path.resolve('dist'), }, module: { rules: [ { test: /\.jsx?$/, loader: 'babel-loader', exclude: /node_modules/, }, { test: /\.css$/, exclude: /node_modules/, use: [ // 将css提取到文件中 MiniCssExtractPlugin.loader, // 处理你的应用程序中的`.css`文件的导入 'css-loader', ], }, ], }, plugins: [ // 将所有的css提取到一个单独的文件中 new MiniCssExtractPlugin({ filename: '[name].css', }), ], }