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:
32
dev/build/esbuild.js
Normal file
32
dev/build/esbuild.js
Normal 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));
|
Reference in New Issue
Block a user