Build: Simplified theatre:build
This commit is contained in:
parent
7c3095ac5a
commit
3950f34533
2 changed files with 65 additions and 12 deletions
60
theatre/devEnv/utils.ts
Normal file
60
theatre/devEnv/utils.ts
Normal file
|
@ -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<typeof build>[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'),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
|
@ -6,18 +6,11 @@
|
||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"typecheck": "tsc --build",
|
"typecheck": "tsc --build",
|
||||||
"build": "run-s _build:clean _build:declarations _build:clean:temp _bundle:production",
|
"build:js": "node -r esbuild-register devEnv/bundle.ts",
|
||||||
"prepare": "run-s build",
|
"build:dts": "run-s typecheck build:dts:bundle",
|
||||||
"_build:clean": "run-s _build:clean:temp _build:clean:dist",
|
"build:dts:bundle": "rollup -c devEnv/declarations-bundler/rollup.config.js",
|
||||||
"_build:clean:temp": "rimraf .temp",
|
"build": "run-p build:dts build:js",
|
||||||
"_build:clean:dist": "rimraf .dist",
|
"prepare": "run-s build"
|
||||||
"_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"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/cli": "^7.14.3",
|
"@babel/cli": "^7.14.3",
|
||||||
|
|
Loading…
Reference in a new issue