-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
packaging: dual-package ui-components with parcel
Parcel[^1] is an alternative to webpack with a few significant differences: 1. Configuration is managed (mostly) through package.json, with minimal configuration actually needed. 2. It's significantly faster than webpack for a package of this size, as it uses native-code packages (e.g. swc) for transformation and minification 3. It has first-class support for ES Module outputs (webpack's support is still experimental) 4. It supports bundling for JS libraries in a mode that bundles only first-party code and *nothing* from node_modules. Use parcel to dual-package ui-components as ESM + CJS, so that bundlers have access to good export analysis (via ESM) and node has access to a format that doesn't require transformation (CJS). As a size comparison, using `du --bytes`: ``` Before (dist/main.js): 774214 B (774KB) After (dist/cjs/index.js): 90701 B ( 90KB) After (dist/esm/index.js): 90232 B ( 90KB) ``` This is possible because no dependencies are included in that bundle. Compared to the previous bundle, the parcel-produced bundles include zero copies of: * lodash (or any part of it) * recharts * @cockroachlabs/icons * anything else in node_modules/ Those dependencies required at runtime are all specified in package.json's 'dependencies' or 'peerDependencies' blocks. Anything in dependencies is automatically downloaded by consumers, but can be successfully de-duped with other compatible node_modules that it uses (i.e. there's no copy of lodash embedded here and another copy in the consumer's node_modules). Similarly, anything in peerDependencies must be provided explicitly by the consuming package (i.e. we declare compatibility with react 17, but installing this package won't even download one into node_modules). The result is a JS bundle that contains only our code, minified for production use in other packages. [^1]: https://parceljs.org
- Loading branch information
Showing
13 changed files
with
1,714 additions
and
1,005 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# This is not a Mercurial repo. | ||
# | ||
# parcel 2.9.3 handles pnpm workspaces strangely, and walks the file system | ||
# upwards looking for a lockfile, a .git file or directory, or a .hg file or | ||
# directory: | ||
# | ||
# https://github.com/parcel-bundler/parcel/blob/5ac45672bb603841bf294c66019930be4354625a/packages/core/core/src/resolveOptions.js#L72 | ||
# | ||
# Without this .hg file, parcel would continue walking to the root of this git | ||
# repo (../../ from here) and install dependencies there. We don't actually want | ||
# that, and would prefer if packages installed for a package were listed in that | ||
# package's dependencies. The presence of this file is enough to keep parcel | ||
# properly rooted within this workspace package, so this .hg file must remain. | ||
# I'm sorry for the confusing naming --- it seems like the least-bad option. | ||
# | ||
# There's an open issue in parcel to address this upstream, but it hasn't been | ||
# resolved as-of September 2023: | ||
# | ||
# https://github.com/parcel-bundler/parcel/issues/7206 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"includePaths": ["node_modules"], | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.