forked from slint-ui/slint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
81 lines (74 loc) · 2.61 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright © SixtyFPS GmbH <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
// TODO: Do build and package wasm-lsp separately. Right now vite does not
// support `exclude` in web workers!
// cSpell: ignore iife lumino
import { defineConfig, UserConfig } from "vite";
export default defineConfig(({ command }) => {
const base_config: UserConfig = {
server: {
fs: {
// Allow serving files from the project root
allow: ["../../"],
},
},
base: "./",
build: {
// We need to enable support for bigint
target: "safari14",
rollupOptions: {
input: {
index: "./index.html",
preview: "./preview.html",
service_worker: "./src/worker/service_worker.ts",
},
output: {
entryFileNames: (assetInfo) => {
return assetInfo.name === "service_worker"
? "[name].js"
: "assets/[name]-[hash].js";
},
},
},
},
worker: {
format: "iife",
},
resolve: {},
};
const global_aliases = {
"@lsp/": "../../../lsp/pkg/",
"~@lumino": "node_modules/@lumino/", // work around strange defaults in @lumino
path: "path-browserify", // To make path.sep available to monaco
};
if (command === "serve") {
// For development builds, serve the wasm interpreter straight out of the local file system.
base_config.resolve = {
alias: {
"@preview/": "../../../api/wasm-interpreter/pkg/",
...global_aliases,
},
};
} else {
// For distribution builds,
// assume deployment on the main website where the loading file (index.js) is in the assets/
// sub-directory and the relative path to the interpreter is as below.
if (base_config.build == null) {
base_config.build = {};
}
base_config.build.rollupOptions = {
makeAbsoluteExternalsRelative: true,
external: [
"../../../../wasm-interpreter/slint_wasm_interpreter.js",
],
...base_config.build.rollupOptions,
};
base_config.resolve = {
alias: {
"@preview/": "../../../../wasm-interpreter/",
...global_aliases,
},
};
}
return base_config as UserConfig;
});