-
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?
Changes from all commits
d15e2ea
8836660
860ee08
04104e5
e508329
d8cf9b9
440ad95
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@lg-charts/legend': minor | ||
| --- | ||
|
|
||
| Updated `@lg-charts/legend` package build configuration to generate both non-minified and minified bundles. The default export is now the non-minified bundle, with the minified bundle provided as a production-specific export. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| '@lg-tools/build': minor | ||
| --- | ||
|
|
||
| Added a new exported `modernDevProdConfig` Rollup configuration, designed for component packages. | ||
|
|
||
| This configuration generates both minified and non-minified bundles to support production and development environments respectively. Please update the `exports` field in your `package.json` to include a `browser.production` entry for both `import` and `require` that points to the minified bundle (`[bundle-name]-min.js`). This ensures that consumers’ build tools use the optimized, minified bundle in production automatically. | ||
|
|
||
| The charts/legend package is the initial adopter of this configuration and is a good example of how to use this new configuration. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,8 +41,18 @@ | |
| ".": { | ||
| "types": "./dist/types/index.d.ts", | ||
| "types@<=5.0": "./dist/types/ts4.9/index.d.ts", | ||
| "import": "./dist/esm/index.js", | ||
| "require": "./dist/umd/index.js" | ||
| "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" | ||
| } | ||
|
Comment on lines
+44
to
+55
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll create a ticket.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Created two sub-tasks for the existing story.
|
||
| } | ||
| }, | ||
| "typesVersions": {} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { | ||
| storiesConfig, | ||
| modernDevProdConfig, | ||
| } from '@lg-tools/build/config/rollup.config.mjs'; | ||
|
|
||
| export default [storiesConfig, modernDevProdConfig]; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ import { getUMDGlobals } from './utils/getUMDGlobals.mjs'; | |
| import { defaultsDeep } from 'lodash-es'; | ||
|
|
||
| const extensions = ['.ts', '.tsx']; | ||
| const testUtilsFilename = 'src/testing/index.ts'; | ||
| const testBundleGlob = 'src/testing/index.ts'; | ||
| const storyGlob = 'src/*.stor{y,ies}.tsx'; | ||
|
|
||
| const babelConfigPath = fileURLToPath( | ||
|
|
@@ -33,43 +33,57 @@ const moduleFormatToDirectory = { | |
| umd: 'dist/umd', | ||
| }; | ||
|
|
||
| const doTestUtilsExist = glob.sync(testUtilsFilename).length > 0; | ||
| /** | ||
| * @param {{ format: import('rollup').OutputOptions['format'], useTerser?: boolean, outputFile?: string, outputName?: string, outputDir?: string }} options | ||
| * @returns {import('rollup').OutputOptions} | ||
| */ | ||
| const createOutput = ({ | ||
| format, | ||
| useTerser = false, | ||
| outputFile = undefined, | ||
| outputName = '[name].js', | ||
| outputDir = moduleFormatToDirectory[format], | ||
| }) => { | ||
| return { | ||
| dir: outputDir, | ||
| file: outputFile, | ||
| name, | ||
| format, | ||
| sourcemap: true, | ||
| globals: format === 'umd' ? getUMDGlobals() : {}, | ||
| validate: true, | ||
| interop: 'compat', // https://rollupjs.org/configuration-options/#output-interop | ||
| entryFileNames: outputName, | ||
| plugins: useTerser ? [terser()] : [], | ||
| }; | ||
| }; | ||
|
|
||
| /** | ||
| * | ||
| * @param {'esm' | 'umd'} format | ||
| * @param {*} overrides | ||
| * @returns | ||
| * @param {import('rollup').RollupOptions['output']} output | ||
| * @param {Partial<import('rollup').RollupOptions>} [overrides] | ||
| * @returns {import('rollup').RollupOptions} | ||
| */ | ||
| const createConfigForFormat = (format, overrides) => { | ||
| const createConfigForFormat = (output, overrides = {}) => { | ||
| /** @type {import('@rollup/plugin-babel').RollupBabelInputPluginOptions} */ | ||
| const babelOptions = { | ||
| babelrc: false, | ||
| babelHelpers: 'bundled', | ||
| extensions, | ||
| configFile: babelConfigPath, | ||
| sourceMaps: true, | ||
| envName: 'production', | ||
| }; | ||
|
|
||
| /** @type {import('rollup').RollupOptions} */ | ||
| const formatConfig = { | ||
| input: ['src/index.ts'], | ||
| output: { | ||
| dir: moduleFormatToDirectory[format], | ||
| name, | ||
| format, | ||
| sourcemap: true, | ||
| globals: format === 'umd' ? getUMDGlobals() : {}, | ||
| validate: true, | ||
| interop: 'compat', // https://rollupjs.org/configuration-options/#output-interop | ||
| }, | ||
| output, | ||
| plugins: [ | ||
| nodePolyfills(), | ||
| nodeExternals({ deps: true }), | ||
| nodeResolve({ extensions }), | ||
|
|
||
| babel({ | ||
| babelrc: false, | ||
| babelHelpers: 'bundled', | ||
| extensions, | ||
| configFile: babelConfigPath, | ||
| sourceMaps: 'inline', | ||
| envName: 'production', | ||
| }), | ||
|
|
||
| babel(babelOptions), | ||
| svgr(), | ||
|
|
||
| terser(), | ||
| ], | ||
| external, | ||
| strictDeprecations: true, | ||
|
|
@@ -83,44 +97,85 @@ const createConfigForFormat = (format, overrides) => { | |
| return finalConfig; | ||
| }; | ||
|
|
||
| const esmConfig = createConfigForFormat('esm'); | ||
| const umdConfig = createConfigForFormat('umd'); | ||
| // 1. Create the default esm/umd bundles configs | ||
| const esmConfig = createConfigForFormat( | ||
| createOutput({ format: 'esm', useTerser: true }), | ||
| ); | ||
| const umdConfig = createConfigForFormat( | ||
| createOutput({ format: 'umd', useTerser: true }), | ||
| ); | ||
|
|
||
| const defaultConfig = [esmConfig, umdConfig]; | ||
|
|
||
| // Add additional entry point to UMD build for test-utils if they exist | ||
| doTestUtilsExist && | ||
| // 1.1. Create the modern dev/prod bundle configs | ||
| const modernDevProdConfig = createConfigForFormat([ | ||
| createOutput({ format: 'esm' }), | ||
| createOutput({ format: 'umd' }), | ||
| createOutput({ | ||
| format: 'esm', | ||
| useTerser: true, | ||
| outputName: '[name]-min.js', | ||
| }), | ||
| createOutput({ | ||
| format: 'umd', | ||
| useTerser: true, | ||
| outputName: '[name]-min.js', | ||
| }), | ||
| ]); | ||
|
|
||
| // 2. Create testing bundles (if applicable) | ||
| const testingBundleEntryPoints = glob.sync(testBundleGlob); | ||
|
|
||
| if (testingBundleEntryPoints.length > 0) { | ||
| defaultConfig.push( | ||
| createConfigForFormat('esm', { | ||
| input: testUtilsFilename, | ||
| output: { | ||
| dir: `${moduleFormatToDirectory['esm']}/testing`, | ||
| createConfigForFormat( | ||
| createOutput({ | ||
| format: 'esm', | ||
| useTerser: true, | ||
| outputDir: `${moduleFormatToDirectory['esm']}/testing`, | ||
| }), | ||
| { | ||
| input: testingBundleEntryPoints, | ||
| }, | ||
| }), | ||
| createConfigForFormat('umd', { | ||
| input: testUtilsFilename, | ||
| output: { | ||
| dir: `${moduleFormatToDirectory['umd']}/testing`, | ||
| ), | ||
| createConfigForFormat( | ||
| createOutput({ | ||
| format: 'umd', | ||
| useTerser: true, | ||
| outputDir: `${moduleFormatToDirectory['umd']}/testing`, | ||
| }), | ||
| { | ||
| input: testingBundleEntryPoints, | ||
| }, | ||
| }), | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| // 3. Create stories bundles (if applicable) | ||
|
|
||
| const storiesEntryPoints = glob.sync(storyGlob); | ||
|
|
||
| // FIXME: Figure out a way to get rid of this. | ||
| // Creates a super-hacky `stories` bundle | ||
| const storiesExist = glob.sync(storyGlob).length > 0; | ||
| const storiesConfig = { | ||
| ...esmConfig, | ||
| input: glob.sync(storyGlob)[0], | ||
| output: { | ||
| format: 'esm', | ||
| file: 'stories.js', | ||
| const storiesConfig = createConfigForFormat( | ||
| { | ||
| ...createOutput({ | ||
| format: 'esm', | ||
| useTerser: true, | ||
| outputDir: null, | ||
| outputFile: 'stories.js', | ||
| }), | ||
| sourcemap: false, | ||
| globals: esmConfig.output.globals, | ||
| }, | ||
| }; | ||
| { | ||
| input: storiesEntryPoints[0], | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a no change, we're ignoring all stories except the first one. doesn't feel right 😁 where do we use this? |
||
| }, | ||
| ); | ||
|
|
||
| storiesExist && defaultConfig.push(storiesConfig); | ||
| if (storiesEntryPoints.length > 0) { | ||
| defaultConfig.push(storiesConfig); | ||
| } | ||
|
|
||
| export { esmConfig, storiesConfig, umdConfig }; | ||
| export { modernDevProdConfig, esmConfig, storiesConfig, umdConfig }; | ||
|
|
||
| export default defaultConfig; | ||
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.productionnecessary? Or can we just haveimport.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.productionfirst, but thebuild:productionscript of MMS did not pick it up. Seems like it's a necessary structure to have the bundler use it.