From b0e6618c81f627a4095569d78ced4f678d3ac23a Mon Sep 17 00:00:00 2001 From: nanaya Date: Fri, 4 Feb 2022 06:40:58 +0900 Subject: [PATCH] Analyze option for build script --- build.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/build.js b/build.js index 04e27f43..c6c23647 100755 --- a/build.js +++ b/build.js @@ -11,6 +11,19 @@ const outfileEsbuildPath = `${outdir}/${outfileEsbuild}` const outfileBabel = 'application.js' const outfileBabelPath = `${outdir}/${outfileBabel}` +const analyzeOnEnd = { + name: 'analyzeOnEnd', + setup (build) { + build.onEnd(async (result) => { + if (options.analyze) { + const analyzeResult = await esbuild.analyzeMetafile(result.metafile) + + console.log(analyzeResult) + } + }) + } +} + const babelOnEnd = { name: 'babelOnEnd', setup (build) { @@ -34,13 +47,20 @@ const babelOnEnd = { } } +const args = process.argv.slice(2) +const options = { + watch: args.includes('--watch'), + analyze: args.includes('--analyze') +} + esbuild.build({ bundle: true, entryPoints: ['app/javascript/application.coffee'], + metafile: options.analyze, nodePaths: ['app/javascript'], outfile: outfileEsbuildPath, - plugins: [coffeeScriptPlugin({ bare: true }), babelOnEnd], + plugins: [coffeeScriptPlugin({ bare: true }), babelOnEnd, analyzeOnEnd], resolveExtensions: ['.coffee', '.js'], sourcemap: true, - watch: process.argv[2] === '--watch' + watch: options.watch })