-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathvite.config.ts
99 lines (93 loc) · 2.52 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
import path from 'path'
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill'
import vue from '@vitejs/plugin-vue'
import { glob } from 'glob'
import { ConfigEnv, defineConfig } from 'vite'
import vuetify from 'vite-plugin-vuetify'
import iife from './build/vite-plugins/vite-plugin-iife'
import webextensionManifest, {
AvailableTarget,
isAvailableTarget,
} from './build/vite-plugins/vite-plugin-manifest'
function contentScriptNames() {
const contentScriptsDir = `${__dirname}/src/content-scripts`
return glob
.sync(`${contentScriptsDir}/**/*.{js,ts}`)
.reduce((result, file) => {
const parsedPath = path.parse(path.relative(contentScriptsDir, file))
const entryName = `${parsedPath.dir}/${parsedPath.name}`
result[entryName] = file
return result
}, {})
}
export default defineConfig((env: ConfigEnv) => {
const input = {
main: 'main.html',
devtools: 'devtools.html',
permission: 'permission.html',
background: 'src/background-worker/background.ts',
...contentScriptNames(),
}
const alias =
env.mode === 'development'
? {
'webextension-polyfill': path.join(
__dirname,
'build/modules/noop.ts',
),
}
: {
querystring: 'rollup-plugin-node-polyfills/polyfills/qs',
url: 'rollup-plugin-node-polyfills/polyfills/url',
util: 'rollup-plugin-node-polyfills/polyfills/util',
}
const buildTarget = process.env.VITE_BUILD_TARGET
if (!isAvailableTarget(buildTarget)) {
const expectedTargets = AvailableTarget.join(', ')
console.error(
`Unexpected build target "${buildTarget}", ${expectedTargets} expected`,
)
process.exit(1)
}
return {
plugins: [
vue(),
vuetify({ autoImport: true }),
iife(Object.keys(input)),
webextensionManifest({
target: buildTarget,
}),
],
css: {
modules: {
generateScopedName: '[name]__[local]',
},
},
resolve: {
alias,
},
optimizeDeps: {
esbuildOptions: {
plugins: [NodeModulesPolyfillPlugin()],
loader: {
'.wasm': 'binary',
},
},
},
build: {
outDir: `dist/${buildTarget}`,
minify: false,
modulePreload: {
pollyfill: false,
},
rollupOptions: {
input,
output: {
assetFileNames: 'assets/[name].[ext]',
chunkFileNames: '[name].js',
entryFileNames: '[name].js',
},
},
},
}
})