-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat: unify manualChunks implementation and support object form regular expressions #6106
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
feat: unify manualChunks implementation and support object form regular expressions #6106
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| private hasLoggedEffect = false; | ||
|
|
||
| hasCachedEffects(): boolean { | ||
| if (!this.included) { |
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.
This was re-added in https://github.com/rollup/rollup/pull/4921/files to solve #4908. This solved the error message but also introduced a test that I think is incorrect. Discussing below on the test itself.
| module.exports = defineTest({ | ||
| description: 'handles manual chunks where the root is not part of the module graph', | ||
| description: | ||
| 'does not output a bundle for the manual chunks that are not part of the module graph', |
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.
I don't think this counts as a breaking change.
With the behavior after #4921, Rollup will artificially output a bundle for the manualChunks pattern provided if it was not in the module graph, but it won't be used by any bundle, unless Rollup merges some dependencies into it, which was the case in this test.
| @@ -1 +1,3 @@ | |||
| import './manual'; | |||
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.
makes sure that manual.js is part of the module graph
| @@ -1 +1,3 @@ | |||
| import './manual'; | |||
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.
makes sure that manual.js is part of the module graph
| }, | ||
| generateError: { | ||
| code: 'INVALID_CHUNK', | ||
| message: 'Cannot assign "dep.js" to the "dep2" chunk as it is already in the "dep1" chunk.' |
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.
This won't happen anymore. I removed the related log error message code.
| }, | ||
| generateError: { | ||
| code: 'EXTERNAL_MODULES_CANNOT_BE_INCLUDED_IN_MANUAL_CHUNKS', | ||
| message: `"${externalModule}" cannot be included in manualChunks because it is resolved as an external module by the "external" option or plugins.` |
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.
This won't happen anymore. I removed the related log error message code.
| }, | ||
| generateError: { | ||
| code: 'EXTERNAL_MODULES_CANNOT_BE_TRANSFORMED_TO_MODULES', | ||
| message: `${externalModule} is resolved as a module now, but it was an external module before. Please check whether there are conflicts in your Rollup options "external" and "manualChunks", manualChunks cannot include external modules.` |
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.
This won't happen anymore. I removed the related log error message code.
ffe5ca7 to
e8682a5
Compare
e8682a5 to
9c83296
Compare
| ``` | ||
|
|
||
| will put all lodash modules into a manual chunk even if you are only using imports of the form `import get from 'lodash/get'`. | ||
| will put all lodash modules into a `lodash` chunk. |
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.
Removed the note about modules not needing to be part of the module graph since this is no longer true. See the manual-chunk-not-included test below.
The PR doesn't affect the behavior outlined in the docs though. I tested on a repro with lodash using import get from 'lodash/get' and the modules were properly grouped together into the lodash chunk. So I guess the statement wasn't really accurate to begin with.
|
Closing, because this approach can lead to non-deterministic behavior. It turns out that manualChunks: {
vendor: ['lodash-es', 'clsx'],
},and manualChunks: (id) => {
if (id.includes('lodash-es')) return 'vendor';
if (id.includes('clsx')) return 'vendor';
},are not the same. In basic use cases such as in this example it is the same and unlikely to pose a problem, but imagine that the developer passes We cannot use I tried to play with some ways to solve the problem, but it seems the best way to be deterministic with the object form is to be through the current logic of |
This PR contains:
Are tests included?
Breaking Changes?
List any relevant issue numbers:
Description
manualChunksobject and function form APIs into the function form implementation. As such, removes theaddManualChunkslogic of the object form and related error messages and tests. I only removed the obvious code, maybe more can be cleaned up.The idea is that when the developer passes
Rollup then converts it to
and then always uses the
assignManualChunkslogic, without theaddStaticDependenciesToManualChunkmerge logic.This will also reduce the changes needed for #6087, and simplify the implementation of
onlyExplicitManualChunks..includes. See closing comment below.