tldraw/apps/vscode/extension/scripts/dev.ts

61 lines
1.4 KiB
TypeScript
Raw Normal View History

2023-04-25 11:01:25 +00:00
import esbuild from 'esbuild'
import { join } from 'path'
import { logEnv } from '../../vscode-script-utils/cli'
import { copyEditor, removeDistDirectory } from '../../vscode-script-utils/helpers'
import { getDirname } from '../../vscode-script-utils/path'
const rootDir = getDirname(import.meta.url, '../')
const log = logEnv('extension')
async function dev() {
await copyEditor({ log })
await removeDistDirectory({ log })
const entryPoints = [join(rootDir, 'src', 'extension.ts')]
log({ cmd: 'esbuild', args: { entryPoints } })
try {
const builder = await esbuild.context({
2023-04-25 11:01:25 +00:00
entryPoints,
outdir: join(rootDir, 'dist', 'web'),
minify: false,
bundle: true,
format: 'cjs',
target: 'es6',
sourcemap: 'inline',
platform: 'node',
define: {
'process.env.NODE_ENV': '"development"',
},
tsconfig: './tsconfig.json',
external: ['vscode'],
plugins: [
{
name: 'log-builds',
setup(build) {
build.onEnd((result) => {
if (result.errors.length) {
log({ cmd: 'esbuild:error', args: { err: result.errors } })
} else {
copyEditor({ log })
log({ cmd: 'esbuild:success', args: {} })
}
})
},
2023-04-25 11:01:25 +00:00
},
],
2023-04-25 11:01:25 +00:00
loader: {
'.woff2': 'dataurl',
'.woff': 'dataurl',
'.svg': 'file',
'.png': 'file',
'.json': 'file',
},
})
await builder.watch()
2023-04-25 11:01:25 +00:00
} catch (error) {
log({ cmd: 'esbuild:error', args: { error } })
throw error
}
}
dev()