Build: Added a watch script

This commit is contained in:
Aria Minaei 2021-06-27 13:40:38 +02:00
parent 22da5ccbfb
commit ff582697c8
4 changed files with 59 additions and 53 deletions

View file

@ -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<typeof build>[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'),
},
})
}
}

View file

@ -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<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'),
},
})
}
}
createBundles(false)

3
theatre/devEnv/watch.ts Normal file
View file

@ -0,0 +1,3 @@
import {createBundles} from './buildUtils'
createBundles(true)

View file

@ -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",