diff --git a/theatre/devEnv/buildUtils.ts b/theatre/devEnv/buildUtils.ts index 48d1038..43665a7 100644 --- a/theatre/devEnv/buildUtils.ts +++ b/theatre/devEnv/buildUtils.ts @@ -1,6 +1,59 @@ +import path from 'path' +import {build} from 'esbuild' + export const definedGlobals = { global: 'window', 'process.env.version': JSON.stringify( require('../studio/package.json').version, ), } + +export function createBundles(watch: boolean) { + for (const which of ['core', 'studio']) { + const pathToPackage = path.join(__dirname, '../', which) + const esbuildConfig: Parameters[0] = { + entryPoints: [path.join(pathToPackage, 'src/index.ts')], + target: ['es6'], + loader: {'.png': 'file'}, + bundle: true, + sourcemap: true, + define: definedGlobals, + watch, + external: ['@theatre/dataverse'], + } + + if (which === 'core') { + esbuildConfig.platform = 'neutral' + esbuildConfig.mainFields = ['browser', 'module', 'main'] + esbuildConfig.target = ['firefox57', 'chrome58'] + esbuildConfig.conditions = ['browser', 'node'] + } + + build({ + ...esbuildConfig, + outfile: path.join(pathToPackage, 'dist/index.cjs'), + format: 'cjs', + }) + + build({ + ...esbuildConfig, + outfile: path.join(pathToPackage, 'dist/index.mjs'), + format: 'esm', + }) + + build({ + ...esbuildConfig, + outfile: path.join(pathToPackage, 'dist/index.min.js'), + format: 'iife', + external: [], + minify: true, + globalName: `Theatre.${which}`, + legalComments: 'external', + platform: 'browser', + define: { + ...definedGlobals, + 'process.env.NODE_ENV': JSON.stringify('production'), + }, + }) + } +} diff --git a/theatre/devEnv/bundle.ts b/theatre/devEnv/bundle.ts index 532f916..8821401 100644 --- a/theatre/devEnv/bundle.ts +++ b/theatre/devEnv/bundle.ts @@ -1,54 +1,3 @@ -import path from 'path' -import {definedGlobals} from './buildUtils' -import {build} from 'esbuild' +import {createBundles} from './buildUtils' -createBundles() - -function createBundles() { - for (const which of ['core', 'studio']) { - const pathToPackage = path.join(__dirname, '../', which) - const esbuildConfig: Parameters[0] = { - entryPoints: [path.join(pathToPackage, 'src/index.ts')], - target: ['firefox88', 'chrome90'], - loader: {'.png': 'file'}, - bundle: true, - sourcemap: true, - define: definedGlobals, - external: ['@theatre/dataverse'], - } - - if (which === 'core') { - esbuildConfig.platform = 'neutral' - esbuildConfig.mainFields = ['browser', 'module', 'main'] - esbuildConfig.target = ['firefox57', 'chrome58'] - esbuildConfig.conditions = ['browser', 'node'] - } - - build({ - ...esbuildConfig, - outfile: path.join(pathToPackage, 'dist/index.cjs'), - format: 'cjs', - }) - - build({ - ...esbuildConfig, - outfile: path.join(pathToPackage, 'dist/index.mjs'), - format: 'esm', - }) - - build({ - ...esbuildConfig, - outfile: path.join(pathToPackage, 'dist/index.min.js'), - format: 'iife', - external: [], - minify: true, - globalName: `Theatre.${which}`, - legalComments: 'external', - platform: 'browser', - define: { - ...definedGlobals, - 'process.env.NODE_ENV': JSON.stringify('production'), - }, - }) - } -} +createBundles(false) diff --git a/theatre/devEnv/watch.ts b/theatre/devEnv/watch.ts new file mode 100644 index 0000000..f8f5d1d --- /dev/null +++ b/theatre/devEnv/watch.ts @@ -0,0 +1,3 @@ +import {createBundles} from './buildUtils' + +createBundles(true) diff --git a/theatre/package.json b/theatre/package.json index a0a4c96..43452aa 100644 --- a/theatre/package.json +++ b/theatre/package.json @@ -7,6 +7,7 @@ "scripts": { "typecheck": "tsc --build", "build:js": "node -r esbuild-register devEnv/bundle.ts", + "build:js:watch": "node -r esbuild-register devEnv/watch.ts", "build:dts": "run-s typecheck build:dts:bundle", "build:dts:bundle": "rollup -c devEnv/declarations-bundler/rollup.config.js", "build": "run-p build:dts build:js",