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
46
47
48
49
50
51
52
53
| const path = require('path');
| const fs = require('fs-extra');
|
| const {
| copyFile,
| distDir,
| customerList,
| updateImportGlob,
| logError,
| restoreImportGlob,
| replaceFileContent,
| exit,
| firstCustomerName,
| checkCustomer,
| formatDate,
| logSuccess,
| logWarn,
| rootDir,
| publicDir
| } = require('./helper');
| const { execSync } = require('child_process');
| if (customerList?.length !== 1) {
| logError(`请正确使用命令 “npm run build customer”(目前只支持一次部署一个)`);
| exit(); // 退出脚本
| }
| checkCustomer('npm run build', firstCustomerName);
| copyFile();
|
|
|
| // 更改 import.meta.glob
| updateImportGlob();
| try {
| execSync('vite build', { stdio: 'inherit' });
| } catch (err) {
| logError(err);
| } finally {
| // 恢复文件
| restoreImportGlob();
| }
|
| //#region ====================== 修改 dist 文件中 index.html 中的引入 js 的 v 值 ======================
|
| const htmlFile = path.join(distDir, 'index.html');
| replaceFileContent(htmlFile, (data) => {
| // 替换为新的 v 值
| const currentStamp = new Date().getTime() + '';
| const newData = data.replace(/(?<=\/static\/config\/.*.js\?v=).*(?=")/g, currentStamp);
| return newData;
| });
| logSuccess(`${formatDate(new Date(), 'HH:MM:SS')} > 🎉🎉🎉【${customerList.join(',')}】项目已成功构建!🎉🎉🎉`);
|
| //#endregion
|
|