Skip to content

Commit 80c45e1

Browse files
committed
fix(options): chunkFilename
chunkFilename should handle string and function options.filename
1 parent 83b3e69 commit 80c45e1

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

src/index.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,18 @@ class MiniCssExtractPlugin {
131131
if (!this.options.chunkFilename) {
132132
const { filename } = this.options;
133133
// Anything changing depending on chunk is fine
134-
if (typeof filename === 'string' && REGEXP_PLACEHOLDERS.test(filename)) {
135-
this.options.chunkFilename = filename;
134+
if (typeof filename === 'string') {
135+
if (REGEXP_PLACEHOLDERS.test(filename)) {
136+
this.options.chunkFilename = filename;
137+
} else {
138+
// Elsewise prefix '[id].' in front of the basename to make it changing
139+
this.options.chunkFilename = filename.replace(
140+
/(^|\/)([^/]*(?:\?|$))/,
141+
'$1[id].$2'
142+
);
143+
}
136144
} else {
137-
// Elsewise prefix '[id].' in front of the basename to make it changing
138-
this.options.chunkFilename = DEFAULT_FILENAME.replace(
139-
/(^|\/)([^/]*(?:\?|$))/,
140-
'$1[id].$2'
141-
);
145+
this.options.chunkFilename = `[id].${DEFAULT_FILENAME}`;
142146
}
143147
}
144148
}

0 commit comments

Comments
 (0)