Skip to content

Commit efa1a4d

Browse files
committed
Add sideEffects: false for old bundlers to know they can tree-shake the CJS
Vite is smart enough to use the ESM build of these packages, but old bundlers like webpack 4 that aren't need a special indicator that files don't have side effects so they can be tree-shaken away. This doesn't change the bundle size with vite, but now webpack should be equivalent. Before: ``` vite v4.4.7 building for production... ✓ 223 modules transformed. dist/api-read-stats.html 230.59 kB │ gzip: 48.89 kB dist/test-bundle-api-read.js 253.91 kB │ gzip: 47.33 kB dist/api-read-stats.html 231.12 kB │ gzip: 48.95 kB dist/test-bundle-api-read.cjs 168.40 kB │ gzip: 39.39 kB ✓ built in 965ms vite v4.4.7 building for production... ✓ 499 modules transformed. dist/react-read-stats.html 321.86 kB │ gzip: 59.00 kB dist/test-bundle-react-read.js 359.09 kB │ gzip: 76.48 kB dist/react-read-stats.html 324.49 kB │ gzip: 59.05 kB dist/test-bundle-react-read.cjs 243.18 kB │ gzip: 64.60 kB ✓ built in 1.34s vite v4.4.7 building for production... ✓ 1033 modules transformed. dist/shopify-read-stats.html 534.09 kB │ gzip: 79.63 kB dist/test-bundle-shopify-read.js 678.46 kB │ gzip: 135.16 kB dist/shopify-read-stats.html 534.63 kB │ gzip: 79.70 kB dist/test-bundle-shopify-read.cjs 477.27 kB │ gzip: 115.70 kB ✓ built in 2.50s ``` After: ``` vite v4.4.7 building for production... ✓ 223 modules transformed. dist/api-read-stats.html 230.59 kB │ gzip: 48.89 kB dist/test-bundle-api-read.js 253.91 kB │ gzip: 47.33 kB dist/api-read-stats.html 231.12 kB │ gzip: 48.95 kB dist/test-bundle-api-read.cjs 168.40 kB │ gzip: 39.39 kB ✓ built in 921ms vite v4.4.7 building for production... ✓ 499 modules transformed. dist/react-read-stats.html 321.86 kB │ gzip: 59.00 kB dist/test-bundle-react-read.js 359.09 kB │ gzip: 76.48 kB dist/react-read-stats.html 324.49 kB │ gzip: 59.05 kB dist/test-bundle-react-read.cjs 243.18 kB │ gzip: 64.60 kB ✓ built in 1.27s vite v4.4.7 building for production... ✓ 1033 modules transformed. dist/shopify-read-stats.html 534.09 kB │ gzip: 79.63 kB dist/test-bundle-shopify-read.js 678.46 kB │ gzip: 135.16 kB dist/shopify-read-stats.html 534.63 kB │ gzip: 79.70 kB dist/test-bundle-shopify-read.cjs 477.27 kB │ gzip: 115.70 kB ✓ built in 2.45s ```
1 parent 5c41db7 commit efa1a4d

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Contributing.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ It can be annoying to work with these packages via `pnpm link` sometimes, so we
1616
- push that to the remote git repo
1717
- and log out a version you can then refer to from other repos
1818

19+
# Checking test bundle sizes
20+
21+
We have a small project setup for evaluating what the bundled size of these dependencies might be together. Run:
22+
23+
```shell
24+
pnpm -F=test-bundles test-build
25+
```
26+
27+
to build the test bundles
28+
1929
# Releasing
2030

2131
Releasing is done automatically via [our release workflow](.github/workflows/release.yml). Any commits to the main branch that changes one of our `packages/**/package.json` versions will automatically be published.

packages/api-client-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
},
2020
"source": "src/index.ts",
2121
"main": "dist/cjs/index.js",
22+
"sideEffects": false,
2223
"scripts": {
2324
"typecheck": "tsc --noEmit",
2425
"build": "rm -rf dist && tsc -b tsconfig.cjs.json tsconfig.esm.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json && echo '{\"type\": \"module\"}' > dist/esm/package.json",

packages/react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
},
2020
"source": "src/index.ts",
2121
"main": "dist/cjs/index.js",
22+
"sideEffects": false,
2223
"scripts": {
2324
"typecheck": "tsc --noEmit",
2425
"build": "rm -rf dist && tsc -b tsconfig.cjs.json tsconfig.esm.json && echo '{\"type\": \"commonjs\"}' > dist/cjs/package.json && echo '{\"type\": \"module\"}' > dist/esm/package.json",

0 commit comments

Comments
 (0)