forked from dfinity/internet-identity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
140 lines (137 loc) · 4.54 KB
/
vite.config.ts
File metadata and controls
140 lines (137 loc) · 4.54 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import { replicaForwardPlugin } from "@dfinity/internet-identity-vite-plugins";
import tailwindcss from "@tailwindcss/vite";
import { readReplicaPort } from "@dfinity/internet-identity-vite-plugins/utils";
import { sveltekit } from "@sveltejs/kit/vite";
import basicSsl from "@vitejs/plugin-basic-ssl";
import { type AliasOptions, type UserConfig, defineConfig } from "vite";
import { nodePolyfills } from "vite-plugin-node-polyfills";
import { lingui } from "@lingui/vite-plugin";
import { sveltePreprocessor } from "./src/lingui-svelte";
import { basename, extname } from "path";
export const aliasConfig: AliasOptions = {
// Polyfill stream for the browser. e.g. needed in "Recovery Phrase" features.
stream: "stream-browserify",
};
export default defineConfig(({ command, mode }): UserConfig => {
// Expand process.env variables with default values to ensure build reproducibility
process.env = {
...process.env,
II_FETCH_ROOT_KEY: `${process.env.II_FETCH_ROOT_KEY ?? "0"}`,
II_DUMMY_AUTH: `${process.env.II_DUMMY_AUTH ?? "0"}`,
II_DUMMY_CAPTCHA: `${process.env.II_DUMMY_CAPTCHA ?? "0"}`,
II_VERSION: `${process.env.II_VERSION ?? ""}`,
};
return {
envPrefix: "II_",
resolve: {
alias: aliasConfig,
},
build: {
assetsInlineLimit: 0,
emptyOutDir: true,
rollupOptions: {
output: {
manualChunks: (id) => {
// Split translations into individual chunks
if (extname(id) === ".po") {
return basename(id);
}
// Keep everything else as is for now (single chunk)
return "index";
},
},
// Bundle only english words in bip39.
external: /.*\/wordlists\/(?!english).*\.json/,
},
commonjsOptions: {
// Source: https://github.com/rollup/plugins/issues/1425#issuecomment-1465626736
strictRequires: true,
},
},
plugins: [
tailwindcss(),
sveltePreprocessor(),
sveltekit(),
lingui(),
// Needed to support WebAuthnIdentity in this repository due to borc dependency.
nodePolyfills({
include: ["buffer"],
}),
[...(process.env.TLS_DEV_SERVER === "1" ? [basicSsl()] : [])],
{
...replicaForwardPlugin({
forwardDomains: ["icp0.io", "ic0.app"],
forwardRules: [
{
hosts: ["nice-name.com"],
canisterName: "test_app",
},
{
hosts: ["nice-issuer-custom-orig.com"],
canisterName: "issuer",
},
...(process.env.NO_HOT_RELOAD === "1"
? [
{
hosts: [
"id.ai",
"identity.ic0.app",
"identity.internetcomputer.org",
],
canisterName:
process.env.SEPARATE_FRONTEND_CANISTER === "1"
? "internet_identity_frontend"
: "internet_identity",
},
...(process.env.SEPARATE_FRONTEND_CANISTER === "1"
? [
{
hosts: ["backend.id.ai"],
canisterName: "internet_identity",
},
]
: []),
]
: []),
],
}),
apply: "serve",
},
],
optimizeDeps: {
esbuildOptions: {
define: {
global: "globalThis",
},
},
},
server:
command !== "serve"
? {}
: {
https: process.env.TLS_DEV_SERVER === "1" ? {} : undefined,
proxy: {
"/api": `http://127.0.0.1:${readReplicaPort()}`,
},
allowedHosts: ["icp-api.io"],
cors: {
origin: [
"https://id.ai",
"https://identity.internetcomputer.org",
"https://identity.ic0.app",
"https://nice-name.com",
"https://nice-issuer-custom-orig.com",
"https://be2us-64aaa-aaaaa-qaabq-cai.icp0.io",
// Test app
"https://bd3sg-teaaa-aaaaa-qaaba-cai.icp0.io",
// Test app
"https://bd3sg-teaaa-aaaaa-qaaba-cai.ic0.app",
// Issuer
"https://bkyz2-fmaaa-aaaaa-qaaaq-cai.icp0.io",
// Issuer
"https://bkyz2-fmaaa-aaaaa-qaaaq-cai.ic0.app",
],
},
},
};
});