比如将 src/assets
中的所有文件复制到 out/assets
,请问如何在 esbuild 的执行过程中完成这个复制操作?
通过 esbuild 插件 esbuild-copy-plugin 解决了,build.js 内容如下
import esbuild from 'esbuild'
import copyPluginPkg from '@sprout2000/esbuild-copy-plugin'
import * as process from 'node:process'
const { copyPlugin } = copyPluginPkg
const isProduction = process.argv.includes('--production')
const options = {
entryPoints: ['./src/extension.ts'],
bundle: true,
outdir: 'out',
packages: 'external',
external: ['vscode'],
format: 'cjs',
sourcemap: !isProduction,
minify: isProduction,
platform: 'node',
plugins: [
copyPlugin({
src: './src/assets',
dest: './out/assets',
}),
],
}
await esbuild.build(options)