卢春龙
2026-08-17 f525b6c3cc105bd1a997d893937689bebcc9570d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;