-
Notifications
You must be signed in to change notification settings - Fork 4.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
Experiment: Use Esbuild as the module bundler #57584
base: trunk
Are you sure you want to change the base?
Conversation
Size Change: 0 B Total Size: 1.69 MB ℹ️ View Unchanged
|
I would go straight with Vite instead of Esbuild or Rollup, to be honest. @luisherranz With that said, Of course that the migration is not going to be trivial. We can start keeping CommonJS as it currently is, and migrate to modules later, when Esbuild/Vite/Rollup are already in place. |
To be honest, I would like the WordPress bundling tool to be so powerful and automatic that no implementation details about which bundler it is using underneath would be exposed. This way, we could start using Esbuild today and, in the future, migrate to another bundler, like Rolldown. That was a crazy idea in the past, but maybe with the maturity that the Javascript ecosystem is reaching and the support of Javascript in browsers, it's something that could be considered. |
This seems ideal. What's stopping that? The main things done with webpack in modules currently off the top of my head are these two:
We need to be able to extract dependencies and some third parties building big plugins do have additional configuration there, but that configuration interface is really defined by DEWP is implemented for webpack but the interface could theoretically be more generic. I doubt the variable replacement has a big impact on bundle size or performance, but I think most compilers do support that so I don't think it should be an issue. |
Yeah, I would like to investigate what modifications the plugins are making to Webpack when using a custom webpack config. I want to see in which cases they need to extend webpack, and if most or all of these modifications could be included by default or with official plugins/configurations. That way, if the internal tool is migrated in the future, those plugins/configurations could also be migrated to the new system. |
I took this and tried to make it work with the actual WordPress packages: #63982 |
What?
Experiment using esbuild as the transpiler and bundler for the modules.
Why?
Because Webpack support for modules is still experimental, it produces a bigger output than necessary, and it doesn't support static and dynamic imports at the same time (it converts all the imports to either static or dynamic, depending on the configuration, see this PR).
How?
I just installed esbuild and created a plugin that replicates what the Dependency Extraction Webpack Plugin does to support modules.
Testing Instructions
Inspect the files in the
test-modules
folder:Run
node esbuild.mjs
to trigger the buildInspect the files created in the
test-modules/build
folder:Check that the
@wordpress/blob
import is dynamic, because it's behind a dynamic import.