Answer the question
In order to leave comments, you need to log in
How to properly apply Webpack 5 plugins for SCCS and CSS?
Good afternoon.
I will describe what the functionality should be:
SCCS and CSS are compiled into one file
Using the autoprefixer, sort-css-media-queries, cssnano plugins
How to make the output have 2 files, one not minified, and the second minified?
How can I add the value of the version specified in package.json to the name of these files?
That is, so that the output is app.css and app.min.1.0.0.css
The code that I write
const path = require('path')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
module.exports = {
mode: 'development',
entry: {
app: path.resolve(__dirname, './src/index.js')
},
output: {
path: path.resolve(__dirname, './dist'),
filename: '[name].js',
},
plugins: [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: '[name].css',
})
],
devServer: {
port: 3300
},
module: {
rules: [
{
// css
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
config: path.resolve(__dirname, 'src/config/postcss.config.js')
}
},
},
],
},
{
// scss
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: {
postcssOptions: {
config: path.resolve(__dirname, 'src/config/postcss.config.js'),
}
},
},
'sass-loader'
]
},
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question