-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
92 lines (87 loc) · 2.58 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
import { resolve } from "path";
import vue from '@vitejs/plugin-vue'
import copy from 'rollup-plugin-copy' // https://www.npmjs.com/package/rollup-plugin-copy
import { fileURLToPath } from "url";
// Extension Configuration
import { outputFolderPath, alias, define, manifestTransform } from './extension';
import buildContentScript from './utils/plugins/build';
// Get Vite Config
export function getViteConfig() {
// https://vitejs.dev/config/
var config = {
mode: process.env.NODE_ENV || 'development', // development, production
root: resolve(__dirname, 'src'),
// publicDir: resolve(__dirname, 'src/assets'),
build: {
// cssCodeSplit: false,
// polyfillModulePreload: false,
outDir: outputFolderPath,
rollupOptions: {
input: {
// Pages
"options": resolve(__dirname, 'src/pages/options/options.html'),
// Background
"service-worker": resolve(__dirname, 'src/background/background'),
},
output: {
entryFileNames: "[name].js",
assetFileNames: "[name].[ext]",
chunkFileNames: "[name][hash].js",
sourcemap: false,
// inlineDynamicImports: true,
}
},
// watch: {},
sourcemap: false,
minify: 'esbuild', // 'terser', // build.terserOptions
emptyOutDir: true,
},
plugins: [
vue(),
copy({
targets: [
{ src: 'src/_locales/*', dest: 'dist/_locales' },
{ src: 'src/assets/*', dest: 'dist/assets' },
{ src: 'src/icons/*', dest: 'dist/icons' },
{
src: "src-" + process.env.BROWSER_TYPE + "/manifest.json",
dest: 'dist',
transform: (contents, filename) => {
var fD = manifestTransform(JSON.parse(contents.toString()))
return Buffer.from(
JSON.stringify({
version: process.env.npm_package_version,
...fD,
})
);
}
}
],
verbose: true,
copyOnce: false,
hook: 'writeBundle'
}),
buildContentScript()
],
// Define Global Variable
define: define,
resolve: {
alias: alias
}
};
if (process.env.NODE_ENV === 'production') {
config.build.minify = 'terser'; // build.terserOptions
// @ts-ignore
config.build.terserOptions = {
format: {
comments: false
},
compress: {
// https://github.com/terser/terser#compress-options
drop_console: true,
drop_debugger: true,
},
};
}
return config
}