forked from rogueg/zen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
58 lines (51 loc) · 1.44 KB
/
build.js
File metadata and controls
58 lines (51 loc) · 1.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const esbuild = require('esbuild')
const yargs = require('yargs')
const { nodeExternalsPlugin } = require('esbuild-node-externals')
const argv = yargs(process.argv)
.alias('w', 'watch')
.describe('w', 'toggle watch mode').argv
async function build() {
// Build the CLI
const ctx = await esbuild.context({
entryPoints: ['lib/cli.ts'],
outfile: 'build/cli.js',
bundle: true,
platform: 'node',
sourcemap: true,
plugins: [nodeExternalsPlugin()],
external: ['chrome-aws-lambda', 'puppeteer-core'],
})
if (argv.watch) {
await ctx.watch()
console.log('Watching for changes...')
} else {
await ctx.rebuild()
await ctx.dispose()
}
}
async function buildSimpleFile(file, outfile, platform = 'browser') {
const ctx = await esbuild.context({
entryPoints: [file],
outfile: `build/${outfile}.js`,
platform,
bundle: true,
sourcemap: true,
plugins: [nodeExternalsPlugin()],
external: ['chrome-aws-lambda', 'puppeteer-core'],
})
if (argv.watch) {
await ctx.watch()
} else {
await ctx.rebuild()
await ctx.dispose()
}
}
build().catch(() => process.exit(1))
buildSimpleFile(
'lib/webpack/webpack-client.ts',
'webpack-client',
'node'
).catch(() => process.exit(1))
buildSimpleFile('lib/latte.ts', 'latte').catch(() => process.exit(1))
buildSimpleFile('lib/worker.js', 'worker').catch(() => process.exit(1))
buildSimpleFile('lib/head.js', 'head').catch(() => process.exit(1))