-
Notifications
You must be signed in to change notification settings - Fork 72
LG-5764 experiment - publishing both non-minified and minified bundles #3325
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
base: main
Are you sure you want to change the base?
LG-5764 experiment - publishing both non-minified and minified bundles #3325
Conversation
🦋 Changeset detectedLatest commit: 5cfe819 The changes in this PR will be included in the next version bump. This PR includes changesets to release 17 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
8461d7d to
e98c775
Compare
71f2868 to
82c6e29
Compare
e98c775 to
b9c5489
Compare
tools/build/src/minify.ts
Outdated
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'm wondering if minification should be part of the rollup build step rather than a separate lg-build minify command? Then where we want it generated for now we could just do so in the package rollup (charts/legend/rollup.config.mjs in this case). What are your thoughts on that?
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.
Hey Terrence, thanks for taking a look. That's definitely possible, but it would require running Rollup twice once with terse plugin and once without it. I was a bit concerned about the overhead of repeating transpilation, polyfilling, and other common steps.
In this approach, I tried to copy Underscore project's build config, which uses Rollup for transpilation and runs Terser as a separate script for minification. I figured that might be a more efficient approach.
Let me know if you like the other approach better or there's a 3rd better option.
https://github.com/jashkenas/underscore/blob/master/package.json
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.
One downside to this approach is that we'd need to update every package's scripts to use lg-build bundle && lg-build minify. I'd rather not do that unless we really need to.
IMO adding the minification as a final step to buildPackage would make the most sense to me (maybe with an optional --minify or --no-minify flag for local development?)
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.
Going the complete opposite direction, we could make a new script in every package, that get s run by turbo:
"packages/<package>/package.json"
{
"scripts": {
"build": "lg-build bundle",
"minify": "lg-build minify"
}
}"package.json"
{
"scripts": {
"build": "turbo run build minify tsc"
}
}"turbo.json"
{
"tasks": {
"minify": {
"dependsOn": ["build"],
}
}
}That said, I still think I prefer combining bundling & minification into one step
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.
Both resonate with me. We should generate both bundles by default, since package.json (which we’ll need to update across all packages) points to both the minified and non-minified bundles.
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.
Folks, great news! While trying a POC on Adam's suggested approach I realized Terrence's proposal was possible. So a single rollup config can have multiple outputs with each output having the flexibility to add another extra plugin (e.g. terser for minification) applied to it.
I'll update the PR today. 🚀
b9c5489 to
e696014
Compare
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.
Pull request overview
This PR implements an experimental dual-bundle publishing strategy for the @lg-charts/legend package, generating both non-minified and minified builds. The non-minified bundle becomes the default export while minified versions are provided for production browser environments, improving debugging capabilities with better source maps and readable stack traces.
Key Changes:
- Refactored Rollup configuration to support multiple output formats with optional minification
- Added production-specific conditional exports to package.json for browser environments
- Created new build tooling to handle minification as a separate step
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tools/build/config/rollup.config.mjs | Refactored to generate both minified and non-minified bundles through new modernDevProdConfig |
| charts/legend/rollup.config.mjs | New rollup config importing modernDevProdConfig for the experimental dual-bundle approach |
| charts/legend/package.json | Updated exports to use conditional browser/production paths for minified bundles |
| .changeset/breezy-groups-turn.md | Documents new minification commands for build tools |
| .changeset/blue-laws-tie.md | Documents legend package build configuration changes |
c93cec3 to
ad378a4
Compare
ad378a4 to
fa18914
Compare
|
Size Change: +30.8 kB (+1.71%) Total Size: 1.83 MB
ℹ️ View Unchanged
|
.changeset/breezy-groups-turn.md
Outdated
| '@lg-tools/cli': minor | ||
| --- | ||
|
|
||
| Introduced new `lg build-minify` and `lg-build minify` commands to separately minify JavaScript bundle files. |
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.
nit: this needs to be updated
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.
Oh, right. I'll update it 🫡
| "import": { | ||
| "browser": { | ||
| "production": "./dist/esm/index-min.js" | ||
| }, | ||
| "default": "./dist/esm/index.js" | ||
| }, | ||
| "require": { | ||
| "browser": { | ||
| "production": "./dist/umd/index-min.js" | ||
| }, | ||
| "default": "./dist/umd/index.js" | ||
| } |
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.
For all my complaining about updating package.json files, I missed that this is necessary to get the dev builds. At least this is optional now though.
We should open a ticket to roll this out across the codebase
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'll create a ticket.
It's a quick job, except icon package that needs a bit of scripting.
I have good context, I can take that on and do it in a day. (not wise to say that ever 😂)
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.
Created two sub-tasks for the existing story.
- Experiment on a package | LG-5764
- Use the finalized approach on all packages | LG-5765
| "import": { | ||
| "browser": { | ||
| "production": "./dist/esm/index-min.js" | ||
| }, | ||
| "default": "./dist/esm/index.js" |
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 remember: is import.browser.production necessary? Or can we just have import.production?
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 tried import.production first, but the build:production script of MMS did not pick it up. Seems like it's a necessary structure to have the bundler use it.
|
Coverage after merging cloudp-352308-env-specific-bundles-experiment into main will be
Coverage Report
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
🎫 Ticket
LG-5764
📝 Description
Added a new
modernDevProdConfigRollup configuration that generates both minified and non-minified bundles in a single pass. Limited to@lg-charts/legendas an experiment. 🧪What changed:
package.jsonexports updated withbrowser.productionentries pointing to minified bundles'inline'to separate.mapfilesWhy:
🧪 Documentation and Testing
@lg-charts/legendpackage, I confirmed locally that both non-minified and minified bundles work on MMS. Also can confirm that the minified bundle gets picked up by MMS's webpack configuration automatically.pnpm changesetand included documentation of changes