const fs = require('fs-extra');
|
const path = require('path');
|
|
// 需要在构建完成后拷贝到产物目录的文件列表
|
// src: 相对于项目根目录的源文件路径
|
// dest: 相对于产物目录(outputPath)的目标文件路径
|
const filesToCopy = [
|
// {
|
// src: 'src/otherPage/pages/carControl/bleMethod.wasm.br',
|
// dest: 'otherPage/pages/carControl/bleMethod.wasm.br',
|
// },
|
{
|
src: 'src/robotaxi/utils/car-control/rtBleMethod.wasm.br',
|
dest: 'robotaxi/utils/car-control/rtBleMethod.wasm.br',
|
},
|
];
|
|
class BuildDonePlugin {
|
apply(compiler) {
|
compiler.hooks.done.tap('BuildDonePlugin', (stats) => {
|
if (process.env.TARO_ENV !== 'weapp') return;
|
|
const outputPath = stats.compilation.outputOptions.path;
|
|
filesToCopy.forEach(({ src, dest }) => {
|
const srcFile = path.resolve(src);
|
const destFile = path.resolve(outputPath, dest);
|
const destDir = path.dirname(destFile);
|
|
if (!fs.existsSync(destDir)) {
|
fs.mkdirSync(destDir, { recursive: true });
|
}
|
|
try {
|
fs.copyFileSync(srcFile, destFile);
|
console.log(`✅ copy: ${src} -> ${dest}`);
|
} catch (error) {
|
console.error(`❌ copy: ${src} -> ${dest}: ${error.message}`);
|
}
|
});
|
});
|
}
|
}
|
|
module.exports = BuildDonePlugin;
|