-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathvite.config.ts
More file actions
73 lines (67 loc) · 2.01 KB
/
vite.config.ts
File metadata and controls
73 lines (67 loc) · 2.01 KB
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
import { fileURLToPath, URL } from "node:url"
import { defineConfig } from "vite"
import vue from "@vitejs/plugin-vue"
import {viteStaticCopy} from "vite-plugin-static-copy";
import * as path from 'path';
import * as fs from 'fs';
import {version} from './package.json'
const copyManifestWithVersion = () => {
return {
name: 'copy-manifest-with-version',
generateBundle() {
const target = process.env.TARGET
if (["firefox", "chrome"].indexOf(target ?? "") === -1) {
throw new Error("Please specify process.env.TARGET 'firefox' or 'chrome'.")
}
const manifestSourcePath = path.resolve(__dirname, `./src/manifest/${target}/manifest.json`)
const manifestContent = fs.readFileSync(manifestSourcePath, 'utf-8').replace('__VERSION__', String(version))
const manifestTargetDir = path.resolve(__dirname, `./dist-${target}/`)
if (!fs.existsSync(manifestTargetDir)){
fs.mkdirSync(manifestTargetDir);
}
const manifestTargetPath = path.resolve(manifestTargetDir, "manifest.json")
fs.writeFileSync(manifestTargetPath, manifestContent, 'utf-8');
}
}
};
export default defineConfig({
plugins: [
vue(),
viteStaticCopy({
targets: [
{
src: "src/icons/*.png",
dest: ""
}
]
}),
copyManifestWithVersion()
],
resolve: {
alias: {
"@": fileURLToPath(new URL("./src", import.meta.url))
}
},
build: {
outDir: `dist-${process.env.TARGET?.toLowerCase()}`,
minify: false,
cssMinify: false,
rollupOptions: {
input: {
BrowserAction: "./browseraction.html",
LazyLoading: "./lazyloading.html",
background: "./src/serviceworker/background.ts"
},
output: {
entryFileNames: (chunkInfo) => {
return chunkInfo.name === 'background' ? 'background.js' : '[name]-[hash].js';
},
manualChunks(id) {
if (id.includes("node_modules")) {
return "vendor";
}
}
}
}
}
})