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 {
|
2023-06-16 10:33:47 +00:00
|
|
|
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'],
|
2023-06-16 10:33:47 +00:00
|
|
|
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-06-16 10:33:47 +00:00
|
|
|
],
|
2023-04-25 11:01:25 +00:00
|
|
|
loader: {
|
|
|
|
'.woff2': 'dataurl',
|
|
|
|
'.woff': 'dataurl',
|
|
|
|
'.svg': 'file',
|
|
|
|
'.png': 'file',
|
|
|
|
'.json': 'file',
|
|
|
|
},
|
|
|
|
})
|
2023-06-16 10:33:47 +00:00
|
|
|
await builder.watch()
|
2023-04-25 11:01:25 +00:00
|
|
|
} catch (error) {
|
|
|
|
log({ cmd: 'esbuild:error', args: { error } })
|
|
|
|
throw error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dev()
|