-
Notifications
You must be signed in to change notification settings - Fork 4
/
vite.config.ts
133 lines (127 loc) · 4.8 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
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
/* eslint-disable @typescript-eslint/ban-ts-comment */
/// <reference types="vitest" />
import { nodeModulesPolyfillPlugin } from 'esbuild-plugins-node-modules-polyfill';
import { defineConfig, configDefaults } from "vitest/config";
import react from "@vitejs/plugin-react";
import { resolve } from "path";
import makeManifest from "./utils/plugins/make-manifest";
import copyContentStyle from "./utils/plugins/copy-content-style";
import rollupNodePolyFill from "rollup-plugin-polyfill-node";
import { isProduction } from "./src/utils/env";
import { loadEnv } from "vite";
import wasm from 'vite-plugin-wasm';
import topLevelAwait from "vite-plugin-top-level-await";
const root = resolve(__dirname, "src");
const entriesDir = resolve(root, "entries");
const assetsDir = resolve(root, "assets");
const hookDir = resolve(root, "hooks");
const utilsDir = resolve(root, "utils");
const stylesDir = resolve(root, "styles");
const outDir = resolve(__dirname, "dist/chrome");
const publicDir = resolve(__dirname, "public");
if (isProduction) {
console.log(`
__ __ __ __ __ __ __
/ | / | / | _ / | / |/ | / |
$$ | /$$/ __ __ _____ ____ ______ $$ | / \\ $$ | ______ $$ |$$ | ______ _$$ |_
$$ |/$$/ / | / |/ \\\\/ \\ / \\ $$ |/$ \\$$ | / \\ $$ |$$ | / \\ / $$ |
$$ $$< $$ | $$ |$$$$$$ $$$$ | $$$$$$ | $$ /$$$ $$ | $$$$$$ |$$ |$$ |/$$$$$$ |$$$$$$/
$$$$$ \\ $$ | $$ |$$ | $$ | $$ | / $$ | $$ $$/$$ $$ | / $$ |$$ |$$ |$$ $$ | $$ | __
$$ |$$ \\ $$ \\__$$ |$$ | $$ | $$ |/$$$$$$$ | $$$$/ $$$$ |/$$$$$$$ |$$ |$$ |$$$$$$$$/ $$ |/ |
$$ | $$ |$$ $$/ $$ | $$ | $$ |$$ $$ | $$$/ $$$ |$$ $$ |$$ |$$ |$$ | $$ $$/
$$/ $$/ $$$$$$/ $$/ $$/ $$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$/ $$/ $$$$$$$/ $$$$/
`);
}
export default ({ mode }: { mode: string }) => {
const env = loadEnv(mode, process.cwd());
return defineConfig({
define: {
"process.env": JSON.stringify({
EXTENSION_PREFIX: env.VITE_EXTENSION_PREFIX || "kuma",
PORT_PREFIX: env.VITE_PORT_PREFIX || "kuma",
}),
},
test: {
fileParallelism: false,
css: false,
globals: true,
environment: "happy-dom",
setupFiles: "src/tests/setup.ts",
coverage: {
reporter: ["text", "html", "lcov", "text-summary"],
exclude: [
...(configDefaults.coverage.exclude as string[]),
"**/src/tests/mocks/**",
"**/src/constants/**",
"**/src/routes/**",
"**/src/components/common/**",
"**/src/xcm/**",
"**/utils/**",
"**/src/entries/**",
"**/tailwind.config.cjs",
"**/postcss.config.cjs",
"**/src/main.tsx",
"**/src/manifest.ts",
"**/src/components/wrapper/*",
"**/src/pages/index.ts",
"**/src/pages/callContract/**",
"**/**/index.ts",
"**/src/components/ui/**",
"**/src/components/icons/**",
"**/src/messageAPI/**",
"**/src/pages/styles/**",
"**/src/pages/settings/components/ManageNetworks.tsx",
"**/src/pages/signMessage/**",
"**/src/pages/swap/base.ts",
],
},
},
resolve: {
alias: {
"@src": root,
"@assets": assetsDir,
"@entries": entriesDir,
"@styles": stylesDir,
"@hooks": hookDir,
"@utils": utilsDir,
buffer: "rollup-plugin-node-polyfills/polyfills/buffer-es6",
},
},
plugins: [react(), topLevelAwait({
promiseExportName: "__tla",
promiseImportName: i => `__tla_${i}`
}),makeManifest(), copyContentStyle(),wasm()],
publicDir,
build: {
chunkSizeWarningLimit: 1000,
outDir,
target: "esnext",
rollupOptions: {
input: {
devtools: resolve(entriesDir, "devtools", "index.html"),
panel: resolve(entriesDir, "panel", "index.html"),
content: resolve(entriesDir, "content", "index.ts"),
background: resolve(entriesDir, "background", "index.ts"),
popup: resolve(entriesDir, "popup", "index.html"),
newtab: resolve(entriesDir, "newtab", "index.html"),
options: resolve(entriesDir, "options", "index.html"),
scripts: resolve(entriesDir, "scripts", "contentScript.ts"),
},
output: {
entryFileNames: (chunk) => `src/entries/${chunk.name}/index.js`,
},
plugins: [rollupNodePolyFill()],
},
},
optimizeDeps: {
esbuildOptions: {
define: {
global: "globalThis",
},
plugins: [
nodeModulesPolyfillPlugin(),
],
},
},
});
};