-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathvite.config.js
86 lines (75 loc) · 1.85 KB
/
vite.config.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { loadEnv } from "vite";
import { resolve } from "path";
import { existsSync } from "fs";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { visualizer } from "rollup-plugin-visualizer";
import { waitChanges, waitOn } from "wx-vite-tools";
import conditionalCompile from "vite-plugin-conditional-compile";
import pkg from "./package.json" with { type: "json" };
export default async ({ mode }) => {
process.env = { ...process.env, ...loadEnv(mode, process.cwd(), "WX") };
const files = [];
if (mode !== "production") {
const paths = [
resolve(__dirname, "../store/dist/index.js"),
resolve(__dirname, "../provider/dist/index.js"),
];
paths.forEach(path => {
if (existsSync(path)) {
files.push(path);
}
});
}
const plugins = [];
if (files.length) plugins.push(waitChanges({ files }));
if (mode !== "development") plugins.push(conditionalCompile());
plugins.push(svelte({}));
const name = pkg.productTag;
let build,
publicDir = resolve(__dirname, "public"),
server = {},
base = "";
if (mode === "test") {
build = {
rollupOptions: {
input: { tests: resolve(__dirname, "tests/index.html") },
},
};
server.port = 5100;
} else {
build = {
rollupOptions: {
input: { index: resolve(__dirname, "index.html") },
},
};
}
if (process.env.WX_BUILD_STATS) {
build = {
lib: {
entry: resolve(__dirname, "src/index.js"),
name,
formats: ["es"],
fileName: format => `${name}.${format}.js`,
},
outDir: "./dist",
sourcemap: true,
minify: true,
target: "esnext",
};
publicDir = false;
plugins.push(visualizer({ filename: "dist/stats.html" }));
}
if (files.length) await waitOn({ files });
return {
base,
build,
publicDir,
resolve: { dedupe: ["svelte"] },
plugins,
server,
watch: {
persistent: true,
include: ["src/**/*.ts", "src/**/*.js"],
},
};
};