-
-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathvite.config.ts
175 lines (154 loc) · 4.71 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
import fs from "node:fs"
import { fileURLToPath } from "node:url"
import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import vueDevTools from "vite-plugin-vue-devtools"
import VueRouter from "unplugin-vue-router/vite"
import AutoImport from "unplugin-auto-import/vite"
import Components from "unplugin-vue-components/vite"
import Icons from "unplugin-icons/vite"
import IconsResolver from "unplugin-icons/resolver"
import TurboConsole from "unplugin-turbo-console/vite"
import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite"
import tailwindcss from "@tailwindcss/vite"
import "dotenv/config"
// @ts-expect-error commonjs module
import { defineViteConfig as define } from "./define.config.mjs"
import { dirname, relative, resolve } from "node:path"
const IS_DEV = process.env.NODE_ENV === "development"
const PORT = Number(process.env.PORT) || 3303
const getImmediateDirectories = (path: string) =>
fs
.readdirSync(path, { withFileTypes: true })
.filter((entry) => entry.isDirectory())
.map((entry) => entry.name)
export default defineConfig({
base: IS_DEV ? `/` : "",
build: {
watch: IS_DEV ? {} : undefined,
sourcemap: IS_DEV ? "inline" : false,
rollupOptions: {
input: {
setup: resolve(__dirname, "src/ui/setup/index.html"),
iframe: resolve(__dirname, "src/ui/content-script-iframe/index.html"),
devtoolsPanel: resolve(__dirname, "src/ui/devtools-panel/index.html"),
},
},
},
css: {
preprocessorOptions: {
scss: {
additionalData: (content, filePath) =>
filePath.includes("content-script/index.scss")
? content
: `@use "/src/assets/base.scss";\n${content}`,
},
},
},
define,
legacy: {
// ⚠️ SECURITY RISK: Allows WebSockets to connect to the vite server without a token check ⚠️
// See https://github.com/crxjs/chrome-extension-tools/issues/971 for more info
// The linked issue gives a potential fix that @crxjs/vite-plugin could implement
skipWebSocketTokenCheck: true,
},
optimizeDeps: {
include: ["vue", "@vueuse/core", "webextension-polyfill"],
exclude: ["vue-demi"],
},
plugins: [
{
name: "ensure-output-dir",
buildStart() {
;["dist/chrome", "dist/firefox"].forEach((dir) => {
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true })
})
},
},
vueDevTools(),
VueI18nPlugin({
include: "src/locales/**",
globalSFCScope: true,
compositionOnly: true,
}),
VueRouter({
dts: "src/types/typed-router.d.ts",
routesFolder: getImmediateDirectories("src/ui").map((dir) => ({
src: `src/ui/${dir}/pages`,
path: `${dir}/`,
})),
}),
vue(),
tailwindcss(),
TurboConsole(),
AutoImport({
imports: [
"vue",
"vue-router",
"pinia",
"@vueuse/core",
{ "vue-router/auto": ["definePage"] },
{ "vue-i18n": ["useI18n", "t"] },
{
"webextension-polyfill": [["=", "browser"]],
},
{ notivue: ["Notivue", "Notification", ["push", "pushNotification"]] },
],
dts: "src/types/auto-imports.d.ts",
dirs: ["src/composables/**", "src/stores/**", "src/utils/**"],
vueTemplate: true,
viteOptimizeDeps: true,
eslintrc: {
enabled: true,
filepath: "src/types/.eslintrc-auto-import.json",
},
}),
Components({
dirs: ["src/components"],
dts: "src/types/components.d.ts",
resolvers: [IconsResolver()],
directoryAsNamespace: true,
globalNamespaces: ["account", "state"],
}),
Icons({
autoInstall: true,
compiler: "vue3",
scale: 1.5,
}),
// rewrite assets to use relative path
{
name: "assets-rewrite",
enforce: "post",
apply: "build",
transformIndexHtml(html, { path }) {
return html.replace(
/"\/assets\//g,
`"${relative(dirname(path), "/assets")}/`,
)
},
},
],
resolve: {
alias: {
"@": fileURLToPath(new URL(".", import.meta.url)),
"~": fileURLToPath(new URL(".", import.meta.url)),
src: fileURLToPath(new URL("src", import.meta.url)),
"@assets": fileURLToPath(new URL("src/assets", import.meta.url)),
},
},
server: {
port: PORT,
hmr: {
host: "localhost",
},
origin: `http://localhost:${PORT}`,
cors: {
origin: [
// ⚠️ SECURITY RISK: Allows any chrome-extension to access the vite server ⚠️
// See https://github.com/crxjs/chrome-extension-tools/issues/971 for more info
// I don't believe that the linked issue mentions a potential solution
/chrome-extension:\/\//,
],
},
},
})