-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathvite.config.ts
44 lines (40 loc) · 1.38 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
import { defineConfig, loadEnv } from 'vite'
import path from 'path'
import vue from '@vitejs/plugin-vue'
import { VitePWA } from 'vite-plugin-pwa'
import { createHtmlPlugin } from 'vite-plugin-html'
import { viteSingleFile } from "vite-plugin-singlefile"
import inject from '@rollup/plugin-inject'
import svgLoader from 'vite-svg-loader'
import pwaOptions from './pwaOptions.js'
import { buildTypes } from './build.js'
declare global { interface Window { BASE_URL: string } }
export default async (config: any) => {
const { command, mode } = config
const env = { ...process.env, ...loadEnv(mode, process.cwd()) }
const singleFile = (() => {
if (mode !== 'file') { return }
env.BASE_URL = './'
return viteSingleFile({ removeViteModuleLoader: true })
})()
return defineConfig({
base: env.BASE_URL ?? '/',
plugins: [
vue(),
createHtmlPlugin({ inject: { data: { ...env } }, minify: true }),
svgLoader({ svgoConfig: { multipass: true } }),
VitePWA(pwaOptions(env)),
singleFile,
buildTypes,
],
resolve: { alias: { '@': path.resolve(__dirname, 'src') } },
build: { target: 'esnext', sourcemap: true, rollupOptions: { plugins: [
inject({ include: ['node_modules/@ledgerhq/**'], modules: { Buffer: ['buffer', 'Buffer'], } }),
] } },
server: { port: 8080, https: false },
define: {
'process.env': {},
'window.BASE_URL': JSON.stringify(env.BASE_URL)
},
})
}