Skip to content

Commit 0fcc123

Browse files
fix: improve contenthash generation
1 parent b197757 commit 0fcc123

File tree

9 files changed

+69
-1
lines changed

9 files changed

+69
-1
lines changed

src/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,21 @@ class MiniCssExtractPlugin {
221221

222222
compilation.hooks.contentHash.tap(pluginName, (chunk) => {
223223
const { outputOptions } = compilation;
224-
const { hashFunction, hashDigest, hashDigestLength } = outputOptions;
224+
const {
225+
hashSalt,
226+
hashDigest,
227+
hashDigestLength,
228+
hashFunction,
229+
} = outputOptions;
225230
const hash = createHash(hashFunction);
226231

232+
if (hashSalt) {
233+
hash.update(hashSalt);
234+
}
235+
236+
hash.update(`${chunk.id} `);
237+
hash.update(chunk.ids ? chunk.ids.join(',') : '');
238+
227239
for (const m of chunk.modulesIterable) {
228240
if (m.type === MODULE_TYPE) {
229241
m.updateHash(hash);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.a {
2+
width: 100px;
3+
}
4+
5+
.b {
6+
width: 100px;
7+
}
8+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.b {
2+
width: 100px;
3+
}
4+
5+
.a {
6+
width: 100px;
7+
}
8+
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const app1 = import('./one');
2+
const app2 = import('./two');
3+
4+
console.log(app1);
5+
console.log(app2);
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import './style1.css';
2+
import './style2.css';
3+
4+
export default 'one';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.a {
2+
width: 100px;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.b {
2+
width: 100px;
3+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import './style2.css';
2+
import './style1.css';
3+
4+
export default 'two';
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Self from '../../../src';
2+
3+
module.exports = {
4+
entry: './index.js',
5+
module: {
6+
rules: [
7+
{
8+
test: /\.css$/,
9+
use: [Self.loader, 'css-loader'],
10+
},
11+
],
12+
},
13+
output: {
14+
filename: '[name].[contenthash].js',
15+
},
16+
plugins: [
17+
new Self({
18+
filename: '[name].[contenthash].css',
19+
}),
20+
],
21+
};

0 commit comments

Comments
 (0)