Skip to content

Commit 541d504

Browse files
bebrawsapegin
andauthored
fix: Fix webpack 5 usage with mini-css-extract-plugin (#42)
It looks like if the plugin is used with mini-css-extract-plugin in webpack 5, `tap` can trigger multiple times. It should trigger only once. Co-authored-by: Artem Sapegin <artem@sapegin.ru>
1 parent 3f773b6 commit 541d504

File tree

12 files changed

+648
-1
lines changed

12 files changed

+648
-1
lines changed

example/package-lock.json

Lines changed: 267 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
"build": "wp"
44
},
55
"dependencies": {
6+
"css-loader": "^5.0.0",
7+
"mini-css-extract-plugin": "^1.1.0",
68
"webpack-nano": "^1.1.0"
79
},
810
"main": "./src/index.js"

example/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import './main.css';
2+
13
const component = (text = 'Hello world') => {
24
const element = document.createElement('div');
35
element.innerHTML = text;

example/src/main.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background: orange;
3+
}

example/webpack.config.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
// eslint-disable-next-line @typescript-eslint/no-var-requires
22
const { MiniHtmlWebpackPlugin } = require('../');
3+
// eslint-disable-next-line @typescript-eslint/no-var-requires
4+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
35

46
module.exports = {
57
mode: 'production',
6-
plugins: [new MiniHtmlWebpackPlugin()],
8+
module: {
9+
rules: [
10+
{
11+
test: /\.css$/,
12+
use: [MiniCssExtractPlugin.loader, 'css-loader'],
13+
},
14+
],
15+
},
16+
plugins: [
17+
new MiniHtmlWebpackPlugin(),
18+
new MiniCssExtractPlugin({
19+
filename: '[name].css',
20+
}),
21+
],
722
};

0 commit comments

Comments
 (0)