Answer the question
In order to leave comments, you need to log in
How to minify multiple CSS with Webpack without concatenating them?
I have a bunch of CSS files that I want to minify. I can combine all CSS into one, but I don't need to. Only some files should be merged. Google did not give a clear answer, I did not find the answer in the documentation.
It should
look like this:
main.css , codehilite.css --> style.min.css
light.css --> light.min.css
dark.css --> dark.min.css
one and the others don't. In general, I'm looking for a way to combine different groups of files into different final files.
I have the following config:
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
module.exports = {
entry: {
'bundle.js': [
path.resolve(__dirname, 'src/index.js')
]
},
output: {
filename: '[name]',
path: path.resolve(__dirname, 'build'),
},
module: {
rules: [
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.(woff|woff2|eot|ttf|svg)$/,
use: {loader: 'url-loader',},
}
],
},
optimization: {
minimize: true,
minimizer: [
new CssMinimizerPlugin({
minimizerOptions: {
preset: [
'default',
{
discardComments: { removeAll: true },
},
],
},
}),
],
},
plugins: [
new MiniCssExtractPlugin({
filename: 'style.min.css'
})
]
};
import './css/main.css';
import './css/codehilite.css';
import './css/light.css';
import './css/dark.css';
Answer the question
In order to leave comments, you need to log in
You can create separate points and import the necessary css files into them.
entry: {
'bundle.js': [
path.resolve(__dirname, 'src/index.js')
],
'light.js': [
path.resolve(__dirname, 'src/light.js')
],
'dark.js': [
path.resolve(__dirname, 'src/dark.js')
],
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question