frontispiece / packages / ink-scriptwriter / build.js
build.js
Raw
const build = require('esbuild').buildSync
const argv = require('minimist')(process.argv.slice(2))

const pkg = require('./package.json')
const shouldWatch = argv.w ? true : false

const baseOptions = {
	entryPoints: [`src/index.ts`],
	sourcemap: true,
	bundle: true,
	assetNames: 'assets/[dir][name]-[hash]',
	platform: 'node',
	metafile: true,
	loader: {
		'.woff': 'dataurl',
		'.woff2': 'dataurl',
		'.png': 'file',
		'.jpg': 'file',
		'.webp': 'file',
		'.basis': 'file',
		'.ktx2': 'file',
		'.ktx': 'file',
		'.stage': 'text',
	},
	plugins: [],
}

if (shouldWatch) {
	baseOptions.watch = {
		onRebuild(error, result) {
			if (error) console.error('watch build failed:', error)
			else console.error('watch build succeeded:', result)
		},
	}
}

const esmOptions = {
	...baseOptions,
	format: 'esm',
	target: ['esnext'],
	outfile: pkg.module,
	define: {
		global: "window",
	},
}
const cjsOptions = {
	...baseOptions,
	platform: 'node',
	outfile: pkg.main,
}

build(esmOptions)
build(cjsOptions)