forked from dfinity/internet-identity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
80 lines (77 loc) · 2.44 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
import { resolve } from "path";
import { AliasOptions, defineConfig, UserConfig } from "vite";
import {
compression,
injectCanisterIdPlugin,
minifyHTML,
stripInjectJsScript,
} from "./vite.plugins";
export const aliasConfig: AliasOptions = {
// Polyfill stream for the browser. e.g. needed in "Recovery Phrase" features.
stream: "stream-browserify",
// Custom alias we are using to shorten and make absolute the imports
$generated: resolve(__dirname, "src/frontend/generated"),
$src: resolve(__dirname, "src/frontend/src"),
$showcase: resolve(__dirname, "src/showcase/src"),
};
export default defineConfig(({ mode }: UserConfig): 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 ?? ""}`,
};
// Path "../../" have to be expressed relative to the "root".
// e.g.
// root = src/frontend
// outDir = ../../dist
return {
root: "src/frontend",
publicDir: "assets",
envPrefix: "II_",
resolve: {
alias: aliasConfig,
},
build: {
assetsInlineLimit: 0,
outDir: "../../dist",
emptyOutDir: true,
rollupOptions: {
// Bundle only english words in bip39.
external: /.*\/wordlists\/(?!english).*\.json/,
output: {
entryFileNames: `[name].js`,
// II canister only supports resources that contains a single dot in their filenames. qr-creator.js.gz = ok. qr-creator.min.js.gz not ok. qr-creator.es6.min.js.gz no ok.
chunkFileNames: ({ name }) => `${name.replace(/.es6|.min/gm, "")}.js`,
assetFileNames: `[name].[ext]`,
},
},
commonjsOptions: {
// Source: https://github.com/rollup/plugins/issues/1425#issuecomment-1465626736
strictRequires: true,
},
},
plugins: [
[...(mode === "development" ? [injectCanisterIdPlugin()] : [])],
[
...(mode === "production"
? [stripInjectJsScript(), minifyHTML(), compression()]
: []),
],
],
optimizeDeps: {
esbuildOptions: {
define: {
global: "globalThis",
},
},
},
server: {
proxy: {
"/api": "http://127.0.0.1:4943",
},
},
};
});