forked from Adamant-im/adamant-im
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite-base.config.ts
More file actions
129 lines (123 loc) · 3.29 KB
/
vite-base.config.ts
File metadata and controls
129 lines (123 loc) · 3.29 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import wasm from 'vite-plugin-wasm'
import path from 'node:path'
import autoprefixer from 'autoprefixer'
import inject from '@rollup/plugin-inject'
import commonjs from '@rollup/plugin-commonjs'
import { fileURLToPath } from 'node:url'
import { deferScripsPlugin } from './vite-config/plugins/deferScriptsPlugin'
import { preloadCSSPlugin } from './vite-config/plugins/preloadCSSPlugin'
import { excludeBip39Wordlists } from './vite-config/rollup/excludeBip39Wordlists'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
import VueDevTools from 'vite-plugin-vue-devtools'
const env = loadEnv('production', process.cwd())
const basePublicPath = env.VITE_PUBLIC_PATH || '/'
const __filename = fileURLToPath(import.meta.url)
const __dirname = path.dirname(__filename)
export default defineConfig({
base: basePublicPath,
plugins: [
wasm(),
VueDevTools(),
vue(),
vueJsx(),
commonjs(),
inject({
Buffer: ['buffer', 'Buffer']
}),
deferScripsPlugin(),
preloadCSSPlugin(),
nodePolyfills({
include: ['util', 'process', 'buffer', 'events', 'stream'],
globals: {
Buffer: true,
process: true
}
})
],
css: {
postcss: {
plugins: [autoprefixer()]
},
preprocessorOptions: {
scss: {
api: 'legacy',
includePaths: ['./src']
}
}
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
// Node.js polyfills
buffer: 'buffer/',
events: 'events/',
stream: 'stream-browserify',
path: 'path-browserify',
crypto: 'crypto-browserify',
http: 'stream-http',
https: 'https-browserify',
os: 'os-browserify/browser',
assert: 'assert',
vm: path.resolve(__dirname, './src/lib/polyfills/vm.js')
},
extensions: ['.tsx', '.ts', '.js', '.json', '.vue']
},
server: {
port: process.env.HTTPS === 'true' ? 5173 : 8080,
https: process.env.HTTPS === 'true' ? {} : undefined
},
// Some old libs like `promise-queue` and `readable-stream` still uses Webpack.
define: {
'process.browser': 'true',
'process.env': {}
},
optimizeDeps: {
include: [
'buffer',
'vite-plugin-node-polyfills/shims/buffer',
'vite-plugin-node-polyfills/shims/global',
'vite-plugin-node-polyfills/shims/process'
],
esbuildOptions: {
// Node.js global to browser globalThis
define: {
global: 'globalThis'
}
}
},
build: {
target: 'esnext',
// Current app bundles include heavy crypto/runtime chunks by design.
// Keep build output clean from non-actionable size warnings.
chunkSizeWarningLimit: 4000,
commonjsOptions: {
include: []
},
rollupOptions: {
external: [...excludeBip39Wordlists()],
output: {
assetFileNames: (assetInfo) => {
if (assetInfo.name.startsWith('materialdesignicons-webfont')) {
return 'assets/[name][extname]'
}
return 'assets/[name]-[hash][extname]'
}
}
}
},
test: {
globals: true,
environment: 'jsdom',
css: {
include: [/.+/]
},
server: {
deps: {
inline: ['vuetify']
}
}
}
})