-
-
Notifications
You must be signed in to change notification settings - Fork 384
feat: allow filename to be a {Function}
#145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
85f6eda
52cf7f6
cf7b731
a06f5df
835624c
44cd88f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,7 +170,7 @@ class MiniCssExtractPlugin { | |
renderedModules, | ||
compilation.runtimeTemplate.requestShortener | ||
), | ||
filenameTemplate: this.options.filename, | ||
filenameTemplate: this.getFilename(chunk, this.options.filename), | ||
pathOptions: { | ||
chunk, | ||
contentHashType: NS, | ||
|
@@ -194,7 +194,10 @@ class MiniCssExtractPlugin { | |
renderedModules, | ||
compilation.runtimeTemplate.requestShortener | ||
), | ||
filenameTemplate: this.options.chunkFilename, | ||
filenameTemplate: this.getFilename( | ||
chunk, | ||
this.options.chunkFilename | ||
), | ||
pathOptions: { | ||
chunk, | ||
contentHashType: NS, | ||
|
@@ -260,7 +263,9 @@ class MiniCssExtractPlugin { | |
if (Object.keys(chunkMap).length > 0) { | ||
const chunkMaps = chunk.getChunkMaps(); | ||
const linkHrefPath = mainTemplate.getAssetPath( | ||
JSON.stringify(this.options.chunkFilename), | ||
JSON.stringify( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd like to see a "safe" stringify done here, or at the very least this done in a try/catch that can safely trap and display a meaningful error message. |
||
this.getFilename(chunk, this.options.chunkFilename) | ||
), | ||
{ | ||
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`, | ||
hashWithLength: (length) => | ||
|
@@ -366,6 +371,16 @@ class MiniCssExtractPlugin { | |
}); | ||
} | ||
|
||
getFilename(chunk, filename) { | ||
console.log('--chunk--'); | ||
console.log(chunk); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove |
||
return this.isFunction(filename) ? filename(chunk) : filename; | ||
} | ||
|
||
isFunction(functionToCheck) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove this and use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't need a separate function here, because it's only called once. Replace the |
||
return typeof functionToCheck === 'function'; | ||
} | ||
|
||
getCssChunkObject(mainChunk) { | ||
const obj = {}; | ||
for (const chunk of mainChunk.getAllAsyncChunks()) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './style.css'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
body { background: red; } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
body { background: red; } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import './style.css'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
body { background: red; } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const Self = require('../../../'); | ||
|
||
module.exports = { | ||
entry: { | ||
index: './index.js', | ||
app: './app.js', | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: [ | ||
Self.loader, | ||
'css-loader', | ||
], | ||
}, | ||
], | ||
}, | ||
plugins: [ | ||
new Self({ | ||
filename: (chunk) => chunk.name == 'app' ? 'this.is.app.css' : `[name].css`, | ||
chunkFilename: (chunk) => '[name].css', | ||
}), | ||
], | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we've got three nested calls here. that's a nightmare for debugging. break these values out into separate
consts
and pass the variables to each function.