recital / core / build.js
build.js
Raw
const build = require('esbuild').build
const argv = require('minimist')(process.argv.slice(2))

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

const baseOptions = {
	entryPoints: [`src/${libraryName}.ts`],
	sourcemap: true,
	bundle: true,
	assetNames: 'assets/[dir][name]-[hash]',
	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)