Skip to content

Commit

Permalink
chore: Improve build
Browse files Browse the repository at this point in the history
  • Loading branch information
maxmilton committed Dec 14, 2024
1 parent 4dbdd9b commit 213b22e
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ console.timeEnd('prebuild');

console.time('build1');

const out = await Bun.build({
const out1 = await Bun.build({
entrypoints: ['src/browser/index.ts'],
outdir: 'dist',
naming: '[dir]/browser.js',
target: 'browser',
minify: true,
sourcemap: 'inline',
});
// TODO: Once bun supports compact iife output, remove this rollup build step.
if (!out1.success) throw new AggregateError(out1.logs, 'Build failed');

// Also use rollup + terser because they generate IIFE code much better than Bun
const bundle = await rollup({
input: out.outputs[0].path,
input: out1.outputs[0].path,
});
await bundle.write({
file: out.outputs[0].path,
format: 'iife',
file: out1.outputs[0].path,
format: 'iife', // must not mutate global scope
name: 'stage1',
sourcemap: true,
plugins: [
Expand All @@ -34,9 +36,15 @@ await bundle.write({
ecma: 2015,
sourceMap: true,
compress: {
reduce_funcs: false, // prevent functions being inlined
comparisons: false,
negate_iife: false,
reduce_funcs: false, // prevent function inlining
passes: 2,
},
format: {
wrap_func_args: true,
wrap_iife: true,
},
});
},
},
Expand All @@ -46,32 +54,35 @@ await bundle.write({
console.timeEnd('build1');
console.time('build2');

await Bun.build({
const out2 = await Bun.build({
entrypoints: ['src/browser/index.ts'],
outdir: 'dist',
target: 'browser',
naming: '[dir]/browser.mjs',
minify: true,
sourcemap: 'linked',
});
if (!out2.success) throw new AggregateError(out2.logs, 'Build failed');

await Bun.build({
const out3 = await Bun.build({
entrypoints: ['src/index.ts'],
outdir: 'dist',
target: 'browser',
minify: true,
sourcemap: 'linked',
});
if (!out3.success) throw new AggregateError(out3.logs, 'Build failed');

await Bun.build({
const out4 = await Bun.build({
entrypoints: ['src/macro.ts'],
outdir: 'dist',
target: 'bun',
minify: true,
sourcemap: 'linked',
});
if (!out4.success) throw new AggregateError(out4.logs, 'Build failed');

await Bun.build({
const out5 = await Bun.build({
entrypoints: [
'src/reconcile/keyed.ts',
'src/reconcile/non-keyed.ts',
Expand All @@ -82,6 +93,7 @@ await Bun.build({
minify: true,
sourcemap: 'linked',
});
if (!out5.success) throw new AggregateError(out5.logs, 'Build failed');

console.timeEnd('build2');
console.time('dts');
Expand Down

0 comments on commit 213b22e

Please sign in to comment.