From 3950f34533c8be1d47162052b6aa1db7171c6654 Mon Sep 17 00:00:00 2001 From: Aria Minaei Date: Fri, 25 Jun 2021 14:37:09 +0200 Subject: [PATCH] Build: Simplified theatre:build --- theatre/devEnv/utils.ts | 60 +++++++++++++++++++++++++++++++++++++++++ theatre/package.json | 17 ++++-------- 2 files changed, 65 insertions(+), 12 deletions(-) create mode 100644 theatre/devEnv/utils.ts diff --git a/theatre/devEnv/utils.ts b/theatre/devEnv/utils.ts new file mode 100644 index 0000000..84a4beb --- /dev/null +++ b/theatre/devEnv/utils.ts @@ -0,0 +1,60 @@ +import path from 'path' +import {build} from 'esbuild' + +export const definedGlobals = { + global: 'window', + 'process.env.version': JSON.stringify( + require('../studio/package.json').version, + ), +} + +const a: any = 'hi' + +export 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'), + }, + }) + } +} diff --git a/theatre/package.json b/theatre/package.json index 2159c72..a0a4c96 100644 --- a/theatre/package.json +++ b/theatre/package.json @@ -6,18 +6,11 @@ ], "scripts": { "typecheck": "tsc --build", - "build": "run-s _build:clean _build:declarations _build:clean:temp _bundle:production", - "prepare": "run-s build", - "_build:clean": "run-s _build:clean:temp _build:clean:dist", - "_build:clean:temp": "rimraf .temp", - "_build:clean:dist": "rimraf .dist", - "_build:declarations": "run-s _build:declarations:emit _build:declarations:bundle", - "_build:declarations:watch": "run-p _build:declarations:emit:watch _build:declarations:bundle:watch", - "_build:declarations:emit": "tsc --build", - "_build:declarations:emit:watch": "tsc --build tsconfig.json --watch --preserveWatchOutput", - "_build:declarations:bundle": "rollup -c devEnv/declarations-bundler/rollup.config.js", - "_build:declarations:bundle:watch": "rollup --watch --no-watch.clearScreen -c devEnv/declarations-bundler/rollup.config.js", - "_bundle:production": "node -r esbuild-register devEnv/bundle.ts" + "build:js": "node -r esbuild-register devEnv/bundle.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", + "prepare": "run-s build" }, "devDependencies": { "@babel/cli": "^7.14.3",