Skip to content

Commit

Permalink
Use better chunkFilename logic
Browse files Browse the repository at this point in the history
  • Loading branch information
sokra committed Mar 4, 2018
1 parent f165d58 commit 959b783
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,17 @@ class MiniCssExtractPlugin {
filename: '[name].css',
}, options);
if (!this.options.chunkFilename) {
// TODO use webpack conversion style here
this.options.chunkFilename = this.options.filename;
const { filename } = this.options;
const hasName = filename.includes('[name]');
const hasId = filename.includes('[id]');
const hasChunkHash = filename.includes('[chunkhash]');
// Anything changing depending on chunk is fine
if (hasChunkHash || hasName || hasId) {
this.options.chunkFilename = filename;
} else {
// Elsewise prefix '[id].' in front of the basename to make it changing
this.options.chunkFilename = filename.replace(/(^|\/)([^/]*(?:\?|$))/, '$1[id].$2');
}
}
}

Expand Down

0 comments on commit 959b783

Please sign in to comment.