-
Notifications
You must be signed in to change notification settings - Fork 84
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
Move from webpack to esbuild bundler #1210
Conversation
@KKoukiou : I updated |
26cd6a4
to
c445ccf
Compare
2a667bf
to
c4b8f61
Compare
Note: Switching from our breakpoint SCSS import dance to rewriting the CSS breakpoints will help detangle our SCSS and will probably make it smaller in the resulting size too. And it'll also fix our breakpoints further (as it's still broken in some places). So it'd probably help here too. Details @ |
This branch is somehow out of date. But when I rebase to main and rebuild node_modules, the bundle sizes are now as we had with webpack. Amazing work! :clap 💯 |
a45703a
to
0a45b86
Compare
The analyzer is cool: Interesting... docker-names is 53 kB I guess it's all the comments which aren't getting stripped? https://github.com/bearjaws/docker-names/blob/master/index.js#L141 Local changes. also requires some dropping of the npm run build output out of the logged json.
|
I found one minor bug when I run
|
@jelly Thanks, well spotted! This needs to be fixed in the plugin in cockpit.git, I'm happy to do that. |
@jelly 's issue is actually much worse.. It also happens with These are both a symptom of a deeper problem: The dist/ directory does not get cleaned between the builds. Do this:
Now dist/ has both the compressed (production) and uncompressed (devel) files. This has already annoyed me a lot with webpack, that does the same. So the use case is to start with a prod build (from e.g. So we need to clean up old files, or possibly all files, in dist/ on each round. webpack has a |
https://esbuild.github.io/api/#outdir documents this behaviour, and basically says "do it yourself". So I added a trivial |
3a7a38e
to
c5a1c47
Compare
Wah, node_modules/ changes every two hours, rebuilt for the 128th time. |
After some discussion with @KKoukiou , I cleaned up how we handle the linters. Pushing with an extra committ which should fail in CI. After this proves to works as intended, I'll take it out again. Update: Failed as intended |
This speeds up the bundle build considerably, from about 26 s with webpack to about 6s with esbuild. Drop babel. esbuild understands JSX natively, and we don't need the "transpile to ES5" any more -- all recent browsers understand ES6. esbuild also creates LEGAL.txt files in development mode (unlike webpack terser), so we can drop this hack as well. Also merge the ESLINT and STYLELINT env vars into a single LINT one, and unify how we handle them. As they dominate the bundler time, let's make sure the linters only run in CI and for watch mode, but not for production builds. Co-Authored-By: Martin Pitt <mpitt@redhat.com>
// always start with a fresh dist/ directory, to change between development and production, or clean up gzipped files | ||
const cleanPlugin = { |
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 suppose this should also eventually move to cockpit's pkg/lib/, but at this point my gut feeling is that we can land this PR, and do that separately. @KKoukiou is already working on esbuild-ifying cockpit.git, and she will most certainly add the clean plugin there as well.
This speeds up the bundle build considerably, from about 26 s with
webpack to about 6s with esbuild.
Drop babel. esbuild understands JSX natively, and we don't need the
"transpile to ES5" any more -- all recent browsers understand ES6.
esbuild also creates LEGAL.txt files in development mode (unlike webpack
terser), so we can drop this hack as well.
Co-Authored-By: Martin Pitt mpitt@redhat.com
TODO:
NODE_ENV=production
esbuild
binary. Bundling in node_modules works for machines/podman/cockpit where we just rpm the pre-built dist/. But not for starter-kit and certificates where rpm build rebuilds the webpack (which is the cleaner approach); so let's restrict that to these projects for now.All credit for this goes to @KKoukiou . I am mostly sending this PR to give it a trial run on CI, and collect a TODO list
Development: Cockpit now supports the esbuild bundler
esbuild is a much faster bundler alternative for webpack. It also natively understands JSX, so that it is not necessary any more to use babel. Cockpit's shared components and bundler plugins in pkg/lib/ now support both eslint and webpack, so that projects can pick either. cockpit-podman moved to esbuild in this commit. You may choose to do the same for your project.