Skip to content

Commit b11ae4a

Browse files
authored
perf: optimizations (#1777)
1 parent a41d909 commit b11ae4a

File tree

248 files changed

+1805
-2124
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

248 files changed

+1805
-2124
lines changed

.changeset/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
"access": "public",
88
"baseBranch": "main",
99
"updateInternalDependencies": "patch",
10-
"ignore": ["docs", "tests"]
10+
"ignore": ["docs", "tests", "@bits-ui/bundle-analyzer"]
1111
}

.changeset/legal-rockets-draw.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"bits-ui": patch
3+
---
4+
5+
perf: optimizations

.github/workflows/bundle-analysis.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
4747
- name: Checkout target branch
4848
run: |
49+
git stash push -m "temp stash for bundle analysis" || true
4950
git fetch origin ${{ github.base_ref }}
5051
git checkout origin/${{ github.base_ref }}
5152
@@ -60,11 +61,14 @@ jobs:
6061
fi
6162
6263
- name: Checkout PR branch
63-
run: git checkout ${{ github.head_ref }}
64+
run: |
65+
git checkout ${{ github.head_ref }}
66+
git stash pop || true
6467
6568
- name: Generate target baseline if missing
6669
if: steps.check-target-bundle.outputs.exists == 'false'
6770
run: |
71+
git stash push -m "temp stash for baseline generation" || true
6872
git checkout origin/${{ github.base_ref }}
6973
pnpm install --frozen-lockfile
7074
pnpm build:packages
@@ -75,6 +79,7 @@ jobs:
7579
echo '{"timestamp":"","results":[]}' > /tmp/bundle-analysis/target-baseline.json
7680
fi
7781
git checkout ${{ github.head_ref }}
82+
git stash pop || true
7883
7984
- name: Generate bundle comparison comment
8085
id: bundle-comment

.oxlintrc.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@
108108
".svelte-kit",
109109
"packages/bits-ui/dist/**/*",
110110
"packages/bits-ui/.svelte-kit/**/*",
111-
"tests/.svelte-kit/**/*"
111+
"tests/.svelte-kit/**/*",
112+
"bundle-analyzer/.temp-bundle-analysis/**/*"
112113
],
113114
"overrides": [
114115
{

bundle-analyzer/bundle-analyzer.ts

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,10 @@ class BundleAnalyzer {
138138
const componentContent = `${namespaceImport}
139139
140140
// test component that uses all exports to ensure they're included in bundle
141-
export function Test${component.name}Component() {
142-
// reference all exports to prevent tree-shaking
143-
const refs = [
144-
${exportReferences}
145-
];
146-
return refs;
147-
}
148-
149-
// ensure all exports are referenced to prevent tree-shaking
150-
export const allExports = [
141+
const refs = [
151142
${exportReferences}
152-
];
143+
];
144+
;(globalThis.__bits_keep ||= []).push(refs);
153145
`;
154146

155147
const filePath = join(this.tempDir, `${component.name}.test.ts`);
@@ -170,7 +162,29 @@ export const allExports = [
170162
template: "raw-data",
171163
gzipSize: true,
172164
}),
165+
{
166+
name: "strip-comments",
167+
generateBundle(options, bundle) {
168+
for (const fileName in bundle) {
169+
const chunk = bundle[fileName];
170+
if (!chunk) continue;
171+
if (chunk.type === "chunk") {
172+
chunk.code = chunk.code
173+
.replace(/\/\*[\s\S]*?\*\//g, "")
174+
.replace(/\/\/.*$/gm, "")
175+
.replace(/^\s*\n/gm, "");
176+
}
177+
}
178+
},
179+
},
173180
],
181+
esbuild: {
182+
minifyWhitespace: true,
183+
minifyIdentifiers: true,
184+
minifySyntax: true,
185+
legalComments: "none",
186+
target: "es2020",
187+
},
174188
build: {
175189
lib: {
176190
entry: entryPath,
@@ -179,7 +193,8 @@ export const allExports = [
179193
},
180194
outDir: outputPath,
181195
write: true,
182-
minify: "terser",
196+
minify: "esbuild",
197+
sourcemap: false,
183198
rollupOptions: {
184199
external: [
185200
"svelte",
@@ -193,6 +208,30 @@ export const allExports = [
193208
],
194209
output: {
195210
manualChunks: undefined,
211+
compact: true,
212+
generatedCode: {
213+
arrowFunctions: true,
214+
constBindings: true,
215+
objectShorthand: true,
216+
reservedNamesAsProps: false,
217+
symbols: true,
218+
preset: "es2015",
219+
},
220+
minifyInternalExports: true,
221+
hoistTransitiveImports: false,
222+
inlineDynamicImports: true,
223+
entryFileNames: "bundle.js",
224+
banner: "",
225+
footer: "",
226+
intro: "",
227+
outro: "",
228+
},
229+
treeshake: {
230+
preset: "smallest",
231+
moduleSideEffects: false,
232+
propertyReadSideEffects: false,
233+
tryCatchDeoptimization: false,
234+
unknownGlobalSideEffects: false,
196235
},
197236
},
198237
},

0 commit comments

Comments
 (0)