utools开发常见问题
# 打包目录不能包含 ".map"、".js.gz" 等调试文件
安装npm i -D rollup-plugin-delete,然后调整vite.config.js
import { defineConfig } from "vite";
import del from "rollup-plugin-delete";
export default defineConfig({
build: {
outDir: "dist",
sourcemap: false,
},
plugins: [
{
...del({
targets: [
"dist/**/*.map",
"dist/**/*.js.gz",
"dist/**/*.css.gz",
"dist/**/*.wasm.gz",
],
hook: "writeBundle",
}),
apply: "build",
},
],
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
或者自己写个小插件
import { defineConfig } from "vite";
import fs from "node:fs";
import path from "node:path";
export default defineConfig({
build: {
outDir: "dist",
sourcemap: false,
},
plugins: [
{
name: "delete-debug-files-after-build",
apply: "build",
closeBundle() {
const dist = path.resolve(__dirname, "dist");
function walk(dir) {
if (!fs.existsSync(dir)) return;
for (const f of fs.readdirSync(dir)) {
const p = path.join(dir, f);
const stat = fs.statSync(p);
if (stat.isDirectory()) {
walk(p);
continue;
}
if (/\.(map|js\.gz|css\.gz|wasm\.gz)$/.test(f)) {
fs.unlinkSync(p);
console.log("🗑️ 已删除:", p);
}
}
}
walk(dist);
},
},
],
});
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
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