diff --git a/packages/core/build.js b/packages/core/build.js index 11e7e1d58..074ec405b 100755 --- a/packages/core/build.js +++ b/packages/core/build.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -import esbuild from 'esbuild' +import * as esbuild from 'esbuild' import { nodeExternalsPlugin } from 'esbuild-node-externals' const watch = process.argv.slice(1).includes('--watch') @@ -9,7 +9,10 @@ const config = { minify: true, sourcemap: true, target: 'es2020', - plugins: [nodeExternalsPlugin()], + plugins: [ + nodeExternalsPlugin(), + rebuildLogger(), + ], } const builds = [ @@ -19,22 +22,39 @@ const builds = [ { entryPoints: ['src/server.ts'], format: 'cjs', outfile: 'dist/server.js', platform: 'node' }, ] -builds.forEach((build) => { - esbuild - .build({ ...config, ...build, ...watcher(build) }) - .then(() => console.log(`${watch ? 'Watching' : 'Built'} ${build.entryPoints} (${build.format})…`)) - .catch(() => process.exit(1)) -}) - -function watcher(build) { - return watch - ? { - watch: { - onRebuild: (error) => - error - ? console.error('Watch failed:', error) - : console.log(`Rebuilding ${build.entryPoints} (${build.format})…`), - }, - } - : {} +try { + const buildContexts = await Promise.all(builds.map(build => esbuild.context({ ...config, ...build }))) + + await Promise.all(buildContexts.map(async (ctx, index) => { + if (watch) { + await ctx.watch() + } else { + await ctx.rebuild() + await ctx.dispose() + } + + console.log(`${watch ? 'Watching' : 'Built'} ${builds[index].entryPoints} (${builds[index].format})...`) + })) + + watch && console.log('Watching for changes. Press Ctrl+C to exit.') +} catch (error) { + process.exit(1) } + +function rebuildLogger() { + return { + name: 'rebuild-logger', + setup(build) { + let ignoreFirstRun = true + + build.onEnd(() => { + if (ignoreFirstRun) { + ignoreFirstRun = false + return + } + + console.log(`Rebuilt ${build.initialOptions.entryPoints} (${build.initialOptions.format})…`) + }) + }, + } +} \ No newline at end of file diff --git a/packages/react/build.js b/packages/react/build.js index 11e7e1d58..074ec405b 100755 --- a/packages/react/build.js +++ b/packages/react/build.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -import esbuild from 'esbuild' +import * as esbuild from 'esbuild' import { nodeExternalsPlugin } from 'esbuild-node-externals' const watch = process.argv.slice(1).includes('--watch') @@ -9,7 +9,10 @@ const config = { minify: true, sourcemap: true, target: 'es2020', - plugins: [nodeExternalsPlugin()], + plugins: [ + nodeExternalsPlugin(), + rebuildLogger(), + ], } const builds = [ @@ -19,22 +22,39 @@ const builds = [ { entryPoints: ['src/server.ts'], format: 'cjs', outfile: 'dist/server.js', platform: 'node' }, ] -builds.forEach((build) => { - esbuild - .build({ ...config, ...build, ...watcher(build) }) - .then(() => console.log(`${watch ? 'Watching' : 'Built'} ${build.entryPoints} (${build.format})…`)) - .catch(() => process.exit(1)) -}) - -function watcher(build) { - return watch - ? { - watch: { - onRebuild: (error) => - error - ? console.error('Watch failed:', error) - : console.log(`Rebuilding ${build.entryPoints} (${build.format})…`), - }, - } - : {} +try { + const buildContexts = await Promise.all(builds.map(build => esbuild.context({ ...config, ...build }))) + + await Promise.all(buildContexts.map(async (ctx, index) => { + if (watch) { + await ctx.watch() + } else { + await ctx.rebuild() + await ctx.dispose() + } + + console.log(`${watch ? 'Watching' : 'Built'} ${builds[index].entryPoints} (${builds[index].format})...`) + })) + + watch && console.log('Watching for changes. Press Ctrl+C to exit.') +} catch (error) { + process.exit(1) } + +function rebuildLogger() { + return { + name: 'rebuild-logger', + setup(build) { + let ignoreFirstRun = true + + build.onEnd(() => { + if (ignoreFirstRun) { + ignoreFirstRun = false + return + } + + console.log(`Rebuilt ${build.initialOptions.entryPoints} (${build.initialOptions.format})…`) + }) + }, + } +} \ No newline at end of file diff --git a/packages/vue2/build.js b/packages/vue2/build.js index 11e7e1d58..074ec405b 100755 --- a/packages/vue2/build.js +++ b/packages/vue2/build.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -import esbuild from 'esbuild' +import * as esbuild from 'esbuild' import { nodeExternalsPlugin } from 'esbuild-node-externals' const watch = process.argv.slice(1).includes('--watch') @@ -9,7 +9,10 @@ const config = { minify: true, sourcemap: true, target: 'es2020', - plugins: [nodeExternalsPlugin()], + plugins: [ + nodeExternalsPlugin(), + rebuildLogger(), + ], } const builds = [ @@ -19,22 +22,39 @@ const builds = [ { entryPoints: ['src/server.ts'], format: 'cjs', outfile: 'dist/server.js', platform: 'node' }, ] -builds.forEach((build) => { - esbuild - .build({ ...config, ...build, ...watcher(build) }) - .then(() => console.log(`${watch ? 'Watching' : 'Built'} ${build.entryPoints} (${build.format})…`)) - .catch(() => process.exit(1)) -}) - -function watcher(build) { - return watch - ? { - watch: { - onRebuild: (error) => - error - ? console.error('Watch failed:', error) - : console.log(`Rebuilding ${build.entryPoints} (${build.format})…`), - }, - } - : {} +try { + const buildContexts = await Promise.all(builds.map(build => esbuild.context({ ...config, ...build }))) + + await Promise.all(buildContexts.map(async (ctx, index) => { + if (watch) { + await ctx.watch() + } else { + await ctx.rebuild() + await ctx.dispose() + } + + console.log(`${watch ? 'Watching' : 'Built'} ${builds[index].entryPoints} (${builds[index].format})...`) + })) + + watch && console.log('Watching for changes. Press Ctrl+C to exit.') +} catch (error) { + process.exit(1) } + +function rebuildLogger() { + return { + name: 'rebuild-logger', + setup(build) { + let ignoreFirstRun = true + + build.onEnd(() => { + if (ignoreFirstRun) { + ignoreFirstRun = false + return + } + + console.log(`Rebuilt ${build.initialOptions.entryPoints} (${build.initialOptions.format})…`) + }) + }, + } +} \ No newline at end of file diff --git a/packages/vue3/build.js b/packages/vue3/build.js index 11e7e1d58..074ec405b 100755 --- a/packages/vue3/build.js +++ b/packages/vue3/build.js @@ -1,5 +1,5 @@ #!/usr/bin/env node -import esbuild from 'esbuild' +import * as esbuild from 'esbuild' import { nodeExternalsPlugin } from 'esbuild-node-externals' const watch = process.argv.slice(1).includes('--watch') @@ -9,7 +9,10 @@ const config = { minify: true, sourcemap: true, target: 'es2020', - plugins: [nodeExternalsPlugin()], + plugins: [ + nodeExternalsPlugin(), + rebuildLogger(), + ], } const builds = [ @@ -19,22 +22,39 @@ const builds = [ { entryPoints: ['src/server.ts'], format: 'cjs', outfile: 'dist/server.js', platform: 'node' }, ] -builds.forEach((build) => { - esbuild - .build({ ...config, ...build, ...watcher(build) }) - .then(() => console.log(`${watch ? 'Watching' : 'Built'} ${build.entryPoints} (${build.format})…`)) - .catch(() => process.exit(1)) -}) - -function watcher(build) { - return watch - ? { - watch: { - onRebuild: (error) => - error - ? console.error('Watch failed:', error) - : console.log(`Rebuilding ${build.entryPoints} (${build.format})…`), - }, - } - : {} +try { + const buildContexts = await Promise.all(builds.map(build => esbuild.context({ ...config, ...build }))) + + await Promise.all(buildContexts.map(async (ctx, index) => { + if (watch) { + await ctx.watch() + } else { + await ctx.rebuild() + await ctx.dispose() + } + + console.log(`${watch ? 'Watching' : 'Built'} ${builds[index].entryPoints} (${builds[index].format})...`) + })) + + watch && console.log('Watching for changes. Press Ctrl+C to exit.') +} catch (error) { + process.exit(1) } + +function rebuildLogger() { + return { + name: 'rebuild-logger', + setup(build) { + let ignoreFirstRun = true + + build.onEnd(() => { + if (ignoreFirstRun) { + ignoreFirstRun = false + return + } + + console.log(`Rebuilt ${build.initialOptions.entryPoints} (${build.initialOptions.format})…`) + }) + }, + } +} \ No newline at end of file