Skip to content

Commit 959b783

Browse files
committed
Use better chunkFilename logic
1 parent f165d58 commit 959b783

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/index.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,17 @@ class MiniCssExtractPlugin {
7171
filename: '[name].css',
7272
}, options);
7373
if (!this.options.chunkFilename) {
74-
// TODO use webpack conversion style here
75-
this.options.chunkFilename = this.options.filename;
74+
const { filename } = this.options;
75+
const hasName = filename.includes('[name]');
76+
const hasId = filename.includes('[id]');
77+
const hasChunkHash = filename.includes('[chunkhash]');
78+
// Anything changing depending on chunk is fine
79+
if (hasChunkHash || hasName || hasId) {
80+
this.options.chunkFilename = filename;
81+
} else {
82+
// Elsewise prefix '[id].' in front of the basename to make it changing
83+
this.options.chunkFilename = filename.replace(/(^|\/)([^/]*(?:\?|$))/, '$1[id].$2');
84+
}
7685
}
7786
}
7887

0 commit comments

Comments
 (0)