2021-08-10 17:19:30 +00:00
|
|
|
/* eslint-disable no-undef */
|
2021-08-13 11:13:11 +00:00
|
|
|
import fs from 'fs'
|
2021-08-10 17:19:30 +00:00
|
|
|
import esbuild from 'esbuild'
|
|
|
|
import serve, { error, log } from 'create-serve'
|
|
|
|
|
|
|
|
const isDevServer = process.argv.includes('--dev')
|
|
|
|
|
|
|
|
esbuild
|
|
|
|
.build({
|
|
|
|
entryPoints: ['src/index.tsx'],
|
|
|
|
bundle: true,
|
2021-09-09 13:58:55 +00:00
|
|
|
outdir: 'dist',
|
2021-08-10 17:19:30 +00:00
|
|
|
minify: false,
|
|
|
|
sourcemap: true,
|
|
|
|
incremental: isDevServer,
|
2021-09-09 12:32:08 +00:00
|
|
|
platform: 'browser',
|
2021-08-10 17:19:30 +00:00
|
|
|
target: ['chrome58', 'firefox57', 'safari11', 'edge18'],
|
|
|
|
define: {
|
|
|
|
'process.env.NODE_ENV': isDevServer ? '"development"' : '"production"',
|
|
|
|
},
|
|
|
|
watch: isDevServer && {
|
|
|
|
onRebuild(err) {
|
|
|
|
serve.update()
|
|
|
|
err ? error('❌ Failed') : log('✅ Updated')
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
.catch(() => process.exit(1))
|
|
|
|
|
2021-09-09 13:58:55 +00:00
|
|
|
for (const file of ['index.html']) {
|
|
|
|
fs.copyFile(`./src/${file}`, `./dist/${file}`, (err) => {
|
|
|
|
if (err) throw err
|
|
|
|
})
|
|
|
|
}
|
2021-08-10 17:19:30 +00:00
|
|
|
if (isDevServer) {
|
|
|
|
serve.start({
|
2021-08-13 12:24:49 +00:00
|
|
|
port: 5000,
|
2021-08-10 17:19:30 +00:00
|
|
|
root: './dist',
|
|
|
|
live: true,
|
|
|
|
})
|
|
|
|
}
|