-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvite.config.ts
62 lines (56 loc) · 1.85 KB
/
vite.config.ts
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
import { defineConfig } from "vite";
import solidPlugin from "vite-plugin-solid";
import { build } from "esbuild";
import { type PluginContext } from "rollup";
// import devtools from 'solid-devtools/vite';
const runBundleScriptBundler = async (ctx: PluginContext) => {
const result = await build({
bundle: true,
minify: true,
entryPoints: ["src/bundle/index.ts"],
outfile: "gen/bundle/index.js",
});
if (result.errors.length > 0) {
ctx.error("Project export script bundling errors: " + result.errors.toString());
}
if (result.warnings.length > 0) {
ctx.warn("Project export script bundling warnings: " + result.warnings.toString());
}
if (result.errors.length === 0) {
ctx.info("Successfully bundled project export script.");
}
};
export default defineConfig(({ mode }) => ({
base: mode === "production" ? "/builder/" : "/",
plugins: [
/*
Uncomment the following line to enable solid-devtools.
For more info see https://github.com/thetarnav/solid-devtools/tree/main/packages/extension#readme
*/
// devtools(),
solidPlugin(),
// This custom plugin (and the function above the defineConfig) use ESBuild to
// bundle src/bundle/index.ts, which is the script linked by every exported project
// bundle. We have to manually call ESBuild because our code needs access to the
// bundled code to put into the project bundle, unlike the typical use-case, where
// the desire is to be able to *run* bundled code.
{
name: "bundle-index",
async buildStart() {
this.addWatchFile("src/bundle/index.ts");
await runBundleScriptBundler(this);
},
async watchChange(id) {
if (id.endsWith("src/bundle/index.ts")) {
await runBundleScriptBundler(this);
}
},
},
],
server: {
port: 3000,
},
build: {
target: "esnext",
},
}));