Commit 68110698e96855b6f2768141451ee5f778d54f43
1 parent
e9e2de36
新增一个打包版本指令
Showing
2 changed files
with
45 additions
and
5 deletions
afterbuild.js
0 → 100644
1 | +const fs = require("fs"); | |
2 | + | |
3 | +const encoding = "UTF-8"; | |
4 | +/** | |
5 | + * 写入version信息方便判断版本 | |
6 | + */ | |
7 | +function sendfile() { | |
8 | + try { | |
9 | + const pathFolder = "./dist/version.text"; | |
10 | + deleteFolder(pathFolder); | |
11 | + fs.writeFileSync(pathFolder, new Date().getTime().toString(), { encoding }); | |
12 | + } catch (e) { | |
13 | + console.error("sourcemap文件写入失败", e); | |
14 | + } | |
15 | +} | |
16 | + | |
17 | +/**删除文件或文件夹 */ | |
18 | +function deleteFolder(path) { | |
19 | + let files = []; | |
20 | + if (fs.existsSync(path)) { | |
21 | + if (fs.statSync(path).isFile()) { | |
22 | + fs.unlinkSync(path); //删除文件 | |
23 | + } else { | |
24 | + files = fs.readdirSync(path); | |
25 | + files.forEach((file, index) => { | |
26 | + let curPath = path + "/" + file; | |
27 | + if (fs.statSync(curPath).isDirectory()) { | |
28 | + // recurse | |
29 | + deleteFolder(curPath); | |
30 | + } else { | |
31 | + // delete file | |
32 | + fs.unlinkSync(curPath); | |
33 | + } | |
34 | + }); | |
35 | + fs.rmdirSync(path); | |
36 | + } | |
37 | + } | |
38 | +} | |
39 | + | |
40 | +sendfile(); | ... | ... |
package.json
... | ... | @@ -5,8 +5,8 @@ |
5 | 5 | "description": "霏微汽车云平台", |
6 | 6 | "scripts": { |
7 | 7 | "analyze": "cross-env ANALYZE=1 umi build", |
8 | - "build:prod": "cross-env REACT_APP_ENV=prod umi build", | |
9 | - "build:unset": "cross-env REACT_APP_ENV=dev umi build", | |
8 | + "build:prod": "cross-env REACT_APP_ENV=prod umi build && node afterbuild.js", | |
9 | + "build:unset": "cross-env REACT_APP_ENV=dev umi build && node afterbuild.js", | |
10 | 10 | "lint": "npm run lint:js && npm run lint:style && npm run lint:prettier", |
11 | 11 | "lint-staged": "lint-staged", |
12 | 12 | "lint-staged:js": "eslint --ext .js,.jsx,.ts,.tsx ", |
... | ... | @@ -14,16 +14,16 @@ |
14 | 14 | "lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./", |
15 | 15 | "lint:prettier": "check-prettier lint", |
16 | 16 | "lint:style": "stylelint --fix \"src/**/*.less\" --syntax less", |
17 | + "package": "chmod +x ./build.sh && ./build.sh", | |
17 | 18 | "prettier": "prettier -c --write \"**/*\"", |
18 | 19 | "site": "cross-env npm run fetch:blocks && npm run build && npm run functions:build", |
19 | 20 | "start": "cross-env HOST=devlocal.feewee.cn umi dev", |
20 | 21 | "start:dev": "cross-env REACT_APP_ENV=dev MOCK=none UMI_UI=none HOST=devlocal.feewee.cn umi dev", |
21 | - "start:test": "cross-env REACT_APP_ENV=test MOCK=none UMI_UI=none HOST=testlocal.feewee.cn umi dev", | |
22 | 22 | "start:prod": "cross-env REACT_APP_ENV=prod MOCK=none UMI_UI=none HOST=local.feewee.cn umi dev", |
23 | + "start:test": "cross-env REACT_APP_ENV=test MOCK=none UMI_UI=none HOST=testlocal.feewee.cn umi dev", | |
23 | 24 | "test": "umi test", |
24 | 25 | "test:all": "node ./tests/run-tests.js", |
25 | - "test:component": "umi test ./src/components", | |
26 | - "package": "chmod +x ./build.sh && ./build.sh" | |
26 | + "test:component": "umi test ./src/components" | |
27 | 27 | }, |
28 | 28 | "husky": { |
29 | 29 | "hooks": {} | ... | ... |