1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-31 15:24:31 +03:00

Extracted esbuild config to a build script

Allows us to use NodeJS code for file/directory locating to not be
shell/os specific, while also also reducing duplicated complexity within
packages.json file.

Related to #3323
This commit is contained in:
Dan Brown
2022-04-13 12:08:56 +01:00
parent c30a9d3564
commit 27339079f7
3 changed files with 216 additions and 184 deletions

32
dev/build/esbuild.js Normal file
View File

@ -0,0 +1,32 @@
#!/usr/bin/env node
const esbuild = require('esbuild');
const fs = require('fs');
const path = require('path');
// Check if we're building for production
// (Set via passing `production` as first argument)
const isProd = process.argv[2] === 'production';
// Gather our input files
const jsInDir = path.join(__dirname, '../../resources/js');
const jsInDirFiles = fs.readdirSync(jsInDir, 'utf8');
const entryFiles = jsInDirFiles
.filter(f => f.endsWith('.js') || f.endsWith('.mjs'))
.map(f => path.join(jsInDir, f));
// Locate our output directory
const outDir = path.join(__dirname, '../../public/dist');
// Build via esbuild
esbuild.build({
bundle: true,
entryPoints: entryFiles,
outdir: outDir,
sourcemap: true,
target: 'es2020',
mainFields: ['module', 'main'],
format: 'esm',
minify: isProd,
logLevel: "info",
}).catch(() => process.exit(1));