Skip to content

Commit 6118455

Browse files
committed
Added configuration and updated README with steps
1 parent ee0c883 commit 6118455

File tree

8 files changed

+3554
-0
lines changed

8 files changed

+3554
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,6 @@ typings/
5959

6060
# next.js build output
6161
.next
62+
63+
# dist folder
64+
dist

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
# mini-css-extract-plugin-contenthash
2+
23
Displays the issue with contenthash in webpack plugin
4+
5+
- Run `yarn build` or `npm run build`
6+
- Comment out `file2` from entry
7+
- Run `build` again
8+
- Notice how `file3.css` is created with a new hash when the contents have not changed

package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "mini-css-extract-plugin-contenthash",
3+
"version": "1.0.0",
4+
"description": "Displays the issue with contenthashes in webpack plugin",
5+
"main": "index.js",
6+
"repository": "https://github.com/lfre/mini-css-extract-plugin-contenthash",
7+
"author": "Alfredo Lopez",
8+
"license": "MIT",
9+
"private": false,
10+
"scripts": {
11+
"build": "webpack"
12+
},
13+
"devDependencies": {
14+
"css-loader": "^1.0.0",
15+
"mini-css-extract-plugin": "^0.4.3",
16+
"node-sass": "^4.9.3",
17+
"sass-loader": "^7.1.0",
18+
"webpack": "^4.19.1",
19+
"webpack-cli": "^3.1.0"
20+
}
21+
}

src/file1.scss

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

src/file2.scss

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

src/file3.scss

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

webpack.config.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
2+
3+
module.exports = {
4+
entry: {
5+
file1: './src/file1.scss',
6+
/*
7+
To display the issue, comment out file2 entry, the contenthash of file3 will change when it shouldn't.
8+
This is due to: https://github.com/webpack/webpack/blob/master/lib/Module.js#L311
9+
Possible fix:
10+
- Assign a consistent id (this.id) to CSSModule https://github.com/webpack-contrib/mini-css-extract-plugin/blob/master/src/index.js#L42
11+
such as `dependency.context`
12+
*/
13+
file2: './src/file2.scss',
14+
file3: './src/file3.scss',
15+
},
16+
mode: 'development',
17+
plugins: [
18+
new MiniCssExtractPlugin({
19+
filename: '[name].[contenthash].css',
20+
}),
21+
],
22+
module: {
23+
rules: [
24+
{
25+
test: /\.scss$/,
26+
use: [
27+
{
28+
loader: MiniCssExtractPlugin.loader,
29+
},
30+
{
31+
loader: 'css-loader', // translates CSS into CommonJS
32+
},
33+
{
34+
loader: 'sass-loader', // compiles Sass to CSS
35+
},
36+
],
37+
},
38+
],
39+
},
40+
};

0 commit comments

Comments
 (0)