-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
output.chunkFilename cannot be a function #2070
Comments
Quoting Tobias:
|
Question: if this is true, how can you determine if you need one chunk to skip the hash, and the rest to have the hash? The problem is we're loading one single common file first, before any of the other entry files in a JSP which doesn't konw anything about the hash. What's the recommended solution in that case? For example:
In that instance, I don't want the webpack.common.js to have the hash as the Java server doesn't know what it is and already contains its own cache busting mechanism. |
What is the actual technical reason blocking this? I've seen it referenced a few times. We don't necessarily need our chunknames to need to be a function, but having the path capable of being a function would work fine. The use case: We have multiple repos being joined together at build time and are generating 1 common chunk, and 1 library chunk using splitChunks. For the moment these files need to be stored in their respective repos because these outputted files are version controlled (we are trying to move away from this though). Even after doing that though, we'd like the files to be put in their respective repo folders so that the application can add preload tags for them. To do that it needs to know they are in a predictable location based on the addon belong to. Right now this is being worked around by adding the requisite file paths into the name and chunkname of each entry. This automated for the initial entries, which I crawl and generate long names with filepaths in them, but the chunknames require them to be manually typed. This works for now but is not feasible long term. Eg. if (richEditor) {
const mountEditor = await import(/* webpackChunkName: "plugins/rich-editor/js/webpack/chunks/mountEditor" */ "@rich-editor/mountEditor");
mountEditor.default(richEditor);
} I'd like to be able to use a function either for the path or the chunkName so we don't need to add bits like |
I'll add my use case where we want to protect some code behind authentication inside an SPA. So we need to move some lazy loaded chunk into a protected folder (based on modules it contains) and keep the rest public. Current workaround is using a plugin to edit chunk name like above to include full path and using |
Had anyone discovered a workaround for this issue? I've just bumped into the same problem. |
I would like to see this too. My use case is when the // if slicing on name was supported
config.output.chunkFilename = 'assets/[name:10].[contenthash].chunk.js';
// or
config.output.chunkFilename = (chunkData) => {
if (chunkData.chunk.name.length > 120) {
return `assets/${truncate(chunkData.chunk.name)}.[contenthash].chunk.js`
}
return 'assets/[name].[contenthash].chunk.js';
}; |
@philostler @alecklandgraf https://webpack.js.org/plugins/source-map-dev-tool-plugin/ can be a great workaround |
@ArthurYidi thanks for pointing me to that! I was missing // attempt to get our sourcemap filenames under 128 characters
config.output.sourceMapFilename = 'assets/sourcemaps/[contenthash].js.map'; |
at the moment I use https://www.npmjs.com/package/chunk-rename-webpack-plugin as a workaround. thx! grettings |
also need function chunkFilename to give conditional chunkFilename |
I used this plugin but got an I'm using webpack 4. Is that the problem? |
I using webpack 4 too, mhh... |
@mahaina |
Let's close in favor webpack/webpack#11530, after merge we will open new issue |
Bug report
What is the current behavior?
When using a function for
output.chunkFilename
, this error is returned:What is the expected behavior?
As per the docs, configuration.output.chunkFilename can be a function.
I would expect this to work in the same way as an
output.filename
function:Version
This issue was moved from webpack/webpack#7090 by @ooflorent. Original issue was by @CLL80.
The text was updated successfully, but these errors were encountered: