Skip to content

Commit 6de4052

Browse files
committed
fix: update Vite config for improved asset handling and browser import
1 parent b57e2d7 commit 6de4052

File tree

2 files changed

+25
-16
lines changed

2 files changed

+25
-16
lines changed

src/types/auto-imports.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ declare module 'vue' {
375375
readonly appRouter: UnwrapRef<typeof import('../utils/router/index')['appRouter']>
376376
readonly asyncComputed: UnwrapRef<typeof import('@vueuse/core')['asyncComputed']>
377377
readonly autoResetRef: UnwrapRef<typeof import('@vueuse/core')['autoResetRef']>
378-
readonly browser: UnwrapRef<typeof import('webextension-polyfill')>
378+
readonly browser: UnwrapRef<typeof import('webextension-polyfill')['=']>
379379
readonly computed: UnwrapRef<typeof import('vue')['computed']>
380380
readonly computedAsync: UnwrapRef<typeof import('@vueuse/core')['computedAsync']>
381381
readonly computedEager: UnwrapRef<typeof import('@vueuse/core')['computedEager']>

vite.config.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import "dotenv/config"
1616

1717
// @ts-expect-error commonjs module
1818
import { defineViteConfig as define } from "./define.config.mjs"
19-
import { resolve } from "node:path"
19+
import { dirname, relative, resolve } from "node:path"
2020

2121
const IS_DEV = process.env.NODE_ENV === "development"
2222
const PORT = Number(process.env.PORT) || 3303
@@ -28,9 +28,11 @@ const getImmediateDirectories = (path: string) =>
2828
.map((entry) => entry.name)
2929

3030
export default defineConfig({
31-
base: IS_DEV ? "/" : "",
31+
base: IS_DEV ? `http://localhost:${PORT}/` : "",
3232

3333
build: {
34+
watch: IS_DEV ? {} : undefined,
35+
sourcemap: IS_DEV ? "inline" : false,
3436
rollupOptions: {
3537
input: {
3638
setup: resolve(__dirname, "src/ui/setup/index.html"),
@@ -105,7 +107,9 @@ export default defineConfig({
105107
"@vueuse/core",
106108
{ "vue-router/auto": ["definePage"] },
107109
{ "vue-i18n": ["useI18n", "t"] },
108-
{ "webextension-polyfill": [["*", "browser"]] },
110+
{
111+
"webextension-polyfill": [["=", "browser"]],
112+
},
109113
{ notivue: ["Notivue", "Notification", ["push", "pushNotification"]] },
110114
],
111115
dts: "src/types/auto-imports.d.ts",
@@ -132,17 +136,18 @@ export default defineConfig({
132136
scale: 1.5,
133137
}),
134138

135-
// {
136-
// name: "assets-rewrite",
137-
// enforce: "post",
138-
// // apply: "build",
139-
// transformIndexHtml(html, { path }) {
140-
// const assetsPath = path
141-
// .replace(/\/[^/]+$/, "/assets")
142-
// .replace(/\\/g, "/")
143-
// return html.replace(/"\/assets\//g, `"${assetsPath}/`)
144-
// },
145-
// },
139+
// rewrite assets to use relative path
140+
{
141+
name: "assets-rewrite",
142+
enforce: "post",
143+
apply: "build",
144+
transformIndexHtml(html, { path }) {
145+
return html.replace(
146+
/"\/assets\//g,
147+
`"${relative(dirname(path), "/assets")}/`,
148+
)
149+
},
150+
},
146151

147152
createHtmlPlugin({ inject: { data: define } }),
148153
],
@@ -155,8 +160,12 @@ export default defineConfig({
155160
"@assets": fileURLToPath(new URL("src/assets", import.meta.url)),
156161
},
157162
},
158-
159163
server: {
164+
port: PORT,
165+
hmr: {
166+
host: "localhost",
167+
},
168+
origin: `http://localhost:${PORT}`,
160169
cors: {
161170
origin: [
162171
// ⚠️ SECURITY RISK: Allows any chrome-extension to access the vite server ⚠️

0 commit comments

Comments
 (0)