-
-
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 all 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,11 @@ class MiniCssExtractPlugin { | |
renderedModules, | ||
compilation.runtimeTemplate.requestShortener | ||
), | ||
filenameTemplate: this.options.filename, | ||
filenameTemplate: this.getFilename( | ||
chunk, | ||
this.options.filename, | ||
this.options.processedFilename | ||
), | ||
pathOptions: { | ||
chunk, | ||
contentHashType: NS, | ||
|
@@ -194,7 +198,11 @@ class MiniCssExtractPlugin { | |
renderedModules, | ||
compilation.runtimeTemplate.requestShortener | ||
), | ||
filenameTemplate: this.options.chunkFilename, | ||
filenameTemplate: this.getFilename( | ||
chunk, | ||
this.options.chunkFilename, | ||
this.options.processedChunkFilename | ||
), | ||
pathOptions: { | ||
chunk, | ||
contentHashType: NS, | ||
|
@@ -260,7 +268,13 @@ class MiniCssExtractPlugin { | |
if (Object.keys(chunkMap).length > 0) { | ||
const chunkMaps = chunk.getChunkMaps(); | ||
const linkHrefPath = mainTemplate.getAssetPath( | ||
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've got three nested calls here. that's a nightmare for debugging. break these values out into separate |
||
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, | ||
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. use destructuring instead of repeating |
||
this.options.processedChunkFilename | ||
) | ||
), | ||
{ | ||
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`, | ||
hashWithLength: (length) => | ||
|
@@ -366,6 +380,19 @@ class MiniCssExtractPlugin { | |
}); | ||
} | ||
|
||
getFilename(chunk, filename, processedFilename) { | ||
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. Is If I'd like to see this use a single |
||
if (!processedFilename) { | ||
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 to do an if with a ternary here: processedFilename = processedFilename || this.isFunction(filename)
? filename(chunk)
: filename; |
||
processedFilename = this.isFunction(filename) | ||
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. 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. Could you 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. I second the parameter reassign, and did not include it in my review because it is mentioned here. this should not be done, and the linter should be throwing a warning there about it. Run |
||
? filename(chunk) | ||
: filename; | ||
} | ||
return processedFilename; | ||
} | ||
|
||
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. 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.
What is this option? There is no documentation about it and it is not used by the test cases.