tldraw/dev/esbuild.config.mjs

45 lines
1,002 B
JavaScript
Raw Normal View History

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'
2021-09-09 16:06:22 +00:00
const isDevServer = true
if (!fs.existsSync('./dist')) {
fs.mkdirSync('./dist')
}
fs.copyFile('./src/index.html', './dist/index.html', (err) => {
if (err) throw err
})
2021-08-10 17:19:30 +00:00
esbuild
.build({
entryPoints: ['src/index.tsx'],
bundle: true,
2021-09-09 16:06:22 +00:00
outfile: 'dist/bundle.js',
2021-08-10 17:19:30 +00:00
minify: false,
sourcemap: true,
incremental: isDevServer,
target: ['chrome58', 'firefox57', 'safari11', 'edge18'],
define: {
'process.env.LIVEBLOCKS_PUBLIC_API_KEY': process.env.LIVEBLOCKS_PUBLIC_API_KEY,
2021-08-10 17:19:30 +00:00
'process.env.NODE_ENV': isDevServer ? '"development"' : '"production"',
},
watch: isDevServer && {
onRebuild(err) {
serve.update()
err ? error('❌ Failed') : log('✅ Updated')
},
},
})
.catch(() => process.exit(1))
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,
})
}