2
0
mirror of https://github.com/moebooru/moebooru synced 2025-08-22 09:57:31 +00:00

Analyze option for build script

This commit is contained in:
nanaya 2022-02-04 06:40:58 +09:00
parent 08e81466cb
commit b0e6618c81

View File

@ -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
})