-
-
Notifications
You must be signed in to change notification settings - Fork 384
"Extracting CSS based on entry" example doesn't work #220
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
Comments
I also had this issue - I logged the object (m) and found the name in this part: _chunks:
SortableSet {
Chunk {
id: null,
ids: null,
debugId: 1035,
name: 'base', // <----This is my entry point name
preventIntegration: false,
entryModule: [Circular],
_modules: [Object],
filenameTemplate: undefined,
_groups: [Object],
files: [],
rendered: false,
hash: undefined,
contentHash: {},
renderedHash: undefined,
chunkReason: undefined,
extraAsync: false,
removedModules: undefined },
_sortFn: [Function: sortById],
_lastActiveSortFn: null,
_cache: undefined,
_cacheOrderIndependent: undefined }, So I modified the function to this: function recursiveIssuer(m) {
if (m.issuer) {
return recursiveIssuer(m.issuer);
} else {
for (var chunk of m._chunks) {
return chunk["name"]
}
return false;
}
} I'm not sure this is the correct way since it requires accessing a private object but I couldn't figure out another way |
hi bro, i also do the same thing you do , but i have find a error that Cannot read property 'pop' of undefined |
I also had this problem. The solution @melissa-hong suggested did not work for me exactly as written, but it did lead me in the right direction, so thanks for that! I think the problem I had with the stated solution above involved using a A colleague, @hieushift, and I came up with two different solutions that both seem to solve the problem, so hopefully they are helpful to others. I am curious, though, if anyone with more experience with this code could comment on whether or not either of these two work-arounds are particularly good or bad? Approach 1 (more similar to approach suggested by docs): UPDATE: This first approach ended up not working. I saw that a css file generated for a different entrypoint was being fetched in the wrong app, and also observed some CSS regressions Assume app entry point is named function recursiveIssuer(m): {
if (m.issuer) {
return recursiveIssuer(m.issuer);
} else {
return Array.from(m._chunks)[0].name;
}
}
optimization.splitChunks.cacheGroups: {
'app-styles': {
name: 'app-styles',
test: (m, c, entry = 'app') => {
return m.constructor.name === 'CssModule' && recursiveIssuer(m) === entry;
},
chunks: 'all',
enforce: true,
}
} Approach 2: No recursive issuer in this approach. Let's assume the name of the entry point is optimization.splitChunks.cacheGroups: {
'app-styles': {
name: 'app-styles',
test: module => module.constructor.name === 'CssModule',
chunks: chunk => chunk.name.startsWith('app'),
enforce: true,
}
} I lean towards thinking approach 1 above is slightly better since we arrive directly at the entry point name for an exact equality check, but still curious what others may think. Note: We use HTMLWebpackPlugin v3.2.0, and do not automatically inject assets into the html template. For both solutions above, in order to make the generated css chunk available as part of (window.webpackJsonp=window.webpackJsonp||[]).push([[0],[]]); I'm not too sure how important or unimportant this small chunk is, so any insight on that would be helpful. The |
This comment has been minimized.
This comment has been minimized.
It is still issue for me. |
/cc @beshanoe problem still exists? |
@evilebottnawi I didn't check yet, but I think so. Even though @njgraf512 suggested some ways to solve it, looks like there's no solid solution yet. And I guess the most confusion is caused by the fact that nobody knows which field of module object to use in order to reliably identify an entrypoint. Cause it's pretty internal to webpack. |
@beshanoe thanks! Somebody can create minimum reproducible test repo, it is allow to identify what is wrong and how better fix it? |
UPDATE: Same issue. Can't create minimum reproducible test repo. Continure investigation
issue
so basically it just doesn't move out weplay-components.css, it leaves it in npm/main-sync-chunk |
Closing due to inactivity. If somebody have problem with example please open new issue with reproducible example, thanks! |
…-webpack-plugin Can filename support function type ? panr#67 webpack-contrib/mini-css-extract-plugin#67 this not work: webpack-contrib/mini-css-extract-plugin#45 (comment) Extracting CSS based on entry also not work webpack-contrib/mini-css-extract-plugin#220
Hello!
I found that the condition in a
cacheGroups
is never true:because module object in the
recursiveIssuer
function doesn't have aname
fieldwebpack: 4.16.2
plugin: 0.4.1
The text was updated successfully, but these errors were encountered: