From 84bca6435171c6d0ac7d04a4ef7246b8d7a0a865 Mon Sep 17 00:00:00 2001 From: Erzbir Date: Thu, 7 Aug 2025 23:35:10 +0800 Subject: [PATCH] chore: refactor build script --- build.js | 72 +++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 45 insertions(+), 27 deletions(-) diff --git a/build.js b/build.js index def12ce..539cae3 100644 --- a/build.js +++ b/build.js @@ -1,32 +1,50 @@ import esbuild from 'esbuild' import {sassPlugin} from 'esbuild-sass-plugin'; +import {readdirSync} from 'fs'; +import {join} from 'path'; -await esbuild.build({ - entryPoints: ['src/main.js'], - bundle: true, - outfile: 'templates/assets/dist/main.js', - assetNames: '[name]', - plugins: [ - sassPlugin(), - ], - loader: { - '.woff': 'file', - '.woff2': 'file', - '.ttf': 'file', - }, - format: 'esm', - target: 'es2020', - minify: true, - sourcemap: false +async function build_main() { + const srcfile = 'src/main.js'; + const outfile = 'templates/assets/dist/main.js'; -}) + await esbuild.build({ + entryPoints: [srcfile], + bundle: true, + outfile: outfile, + assetNames: '[name]', + plugins: [ + sassPlugin(), + ], + loader: { + '.woff': 'file', + '.woff2': 'file', + '.ttf': 'file', + }, + format: 'esm', + target: 'es2020', + minify: true, + sourcemap: false + }) +} -await esbuild.build({ - entryPoints: ['src/libs/pjax.js'], - bundle: true, - outfile: 'templates/assets/dist/libs/pjax.js', - format: 'esm', - target: 'es2020', - minify: true, - sourcemap: false -}); \ No newline at end of file + +async function build_libs() { + const srcDir = 'src/libs'; + const outDir = 'templates/assets/dist/libs'; + + await esbuild.build({ + entryPoints: readdirSync(srcDir) + .filter(file => file.endsWith('.js')) + .map(file => join(srcDir, file)), + bundle: true, + outdir: outDir, + format: 'esm', + target: 'es2020', + minify: true, + splitting: false, + sourcemap: false + }); +} + +await build_main(); +await build_libs(); \ No newline at end of file