-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
Tech: migrate to es version of lodash (and shows dist size stats) #20910
Conversation
OK this makes sense.. the reason tree-shaking barely seems to work is because of this: storybook/code/ui/manager/src/globals/runtime.ts Lines 4 to 10 in 43f93bb
In short: I tested this by adding: // code/lib/manager-api/src/index.tsx
export const THIS_IS_A_TREESHAKING_TEST = true; Which is then never ever used anywhere... But it's still preserved in the manager prebundled code, because.. we load it as a So.. to get smaller prebundles, we need to limit our public API. |
This depends on this: ComponentDriven/csf#62 getting merged. |
@@ -117,11 +120,24 @@ const run = async ({ cwd, flags }: { cwd: string; flags: string[] }) => { | |||
platform: platform || 'browser', | |||
external: externals, | |||
|
|||
esbuildPlugins: [ | |||
esbuildAliasPlugin({ | |||
lodash: 'lodash-es', |
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.
If we alias all occurrences of lodash to lodash-es
, we have to also make sure, that lodash-es is installed for every package. Does the aliasing also encounter for lodash usage in node_modules? If so, how can we even be sure, that the right version of lodash-es is installed instead? Can you explain this part to me. I am a bit confused.
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 have to also make sure, that lodash-es is installed for every package
yes
Does the aliasing also encounter for lodash usage in node_modules?
Sort of, when the bundler is following the modules-graph up, it will encounter imports to lodash
and swap it out.
However when it encounters a module that's external, it will skip, and leave the import as-is.
This means if package-a
depends on lodash
, but package-a
is externalized, it will NOT be swapped.
esbuildAliasPlugin({ | ||
lodash: 'lodash-es', | ||
}), | ||
lodashTransformer({ |
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.
Why do we need this plugin? Is tree-shaking not correctly working for lodash-es? Or do we want to accommodate all lodash
usages, which we haven't swapped out by lodash-es
?
plugins: [ | ||
{ | ||
name: 'lodash', | ||
async renderChunk(code) { | ||
return { code: code.replaceAll('lodash-es', 'lodash') }; | ||
}, | ||
}, | ||
], | ||
esbuildPlugins: [ | ||
esbuildAliasPlugin({ | ||
'lodash-es': require.resolve('lodash'), | ||
}), | ||
], |
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 understand this. Can you explain it to me?
No description provided.