-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
46 lines (46 loc) · 1.22 KB
/
index.js
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
import fs from "fs-extra";
console.log(fs);
export default function vitePluginEarthsdk(){
let outDir = "dist";
let base = "./";
return {
name: "vitePluginEarthsdk",
async config(config, { command }) {
if (!config.base) {
config.base=base
}
if (command == "serve") {
//develop引入earth包
try {
await fs.copy("node_modules/earthsdk/dist/XbsjCesium", "public/XbsjCesium");
await fs.copy("node_modules/earthsdk/dist/XbsjEarth", "public/XbsjEarth");
} catch (err) {
console.error("copy failed", err);
}
} else {
outDir = config.build.outDir;
}
},
async closeBundle() {
//product引入earth包
try {
await fs.copy("node_modules/earthsdk/dist/XbsjCesium", outDir + "/XbsjCesium");
await fs.copy("node_modules/earthsdk/dist/XbsjEarth", outDir + "/XbsjEarth");
} catch (err) {
console.error("copy failed", err);
}
},
transformIndexHtml() {
//index.html script引入
return [
{
tag: "script",
attrs: {
src: "XbsjEarth/XbsjEarth.js",
},
injectTo: "head-prepend",
},
];
},
};
}