-
-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathvite.firefox.config.ts
115 lines (104 loc) · 2.72 KB
/
vite.firefox.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
import { crx } from "@crxjs/vite-plugin"
import { defineConfig } from "vite"
import zipPack from "vite-plugin-zip-pack"
import manifest from "./manifest.firefox.config"
import packageJson from "./package.json" with { type: "json" }
import ViteConfig from "./vite.config"
import chalk from "chalk"
const IS_DEV = process.env.NODE_ENV === "development"
const browser = "firefox"
const outDir = "dist"
const browserOutDir = `${outDir}/${browser}`
const outFileName = `${browser}-${packageJson.version}.zip`
function printDevMessage() {
setTimeout(() => {
console.info("\n")
console.info(
`${chalk.greenBright(`✅ Successfully built for ${browser}.`)}`,
)
console.info(
chalk.greenBright(
`🚀 To load this extension in Firefox, go to about:debugging, click "This Firefox", then click "Load Temporary Add-on" and select the extension's manifest file in ${browserOutDir}.`,
),
)
console.info("\n")
}, 50)
}
function printProdMessage() {
setTimeout(() => {
console.info("\n")
console.info(
`${chalk.greenBright(`✅ Successfully built for ${browser}.`)}`,
)
console.info(
`${chalk.greenBright(`📦 Zip File for ${browser} is located at ${outDir}/${outFileName}. You can upload this to respective store. `)}`,
)
console.info(
chalk.greenBright(
`🚀 To load this extension in Firefox, go to about:debugging, click "This Firefox", then click "Load Temporary Add-on" and select the extension's manifest file in ${browserOutDir}.`,
),
)
console.info("\n")
}, 50)
}
if (!ViteConfig.build) {
ViteConfig.build = {}
}
if (!ViteConfig.plugins) {
ViteConfig.plugins = []
}
ViteConfig.build.outDir = browserOutDir
if (IS_DEV) {
ViteConfig.build.minify = false
ViteConfig.build.sourcemap = true
}
ViteConfig.plugins.unshift(
crx({
manifest,
browser,
contentScripts: {
injectCss: true,
},
}),
)
if (IS_DEV) {
ViteConfig.plugins.push({
name: "vite-plugin-build-message",
enforce: "post",
configureServer(server) {
server.httpServer?.once("listening", () => {
printDevMessage()
})
},
closeBundle: {
sequential: true,
handler() {
printDevMessage()
},
},
})
} else {
ViteConfig.plugins.push(
zipPack({
inDir: browserOutDir,
outDir,
outFileName,
filter: (fileName, filePath, isDirectory) =>
!(isDirectory && filePath.includes(".vite")),
}),
)
ViteConfig.plugins.push({
name: "vite-plugin-build-message",
enforce: "post",
closeBundle: {
sequential: true,
handler() {
printProdMessage()
},
},
})
}
// https://vitejs.dev/config/
export default defineConfig({
...ViteConfig,
})