-
Notifications
You must be signed in to change notification settings - Fork 198
/
Copy pathvite.config.js
106 lines (101 loc) · 2.3 KB
/
vite.config.js
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
import { resolve } from 'node:path'
import { defineConfig } from 'vite'
import { languageFileOptions, enUS } from '@draggable/formeo-languages'
import banner from 'vite-plugin-banner'
import compression from 'vite-plugin-compression'
import { createHtmlPlugin } from 'vite-plugin-html'
import pkg from './package.json'
const bannerTemplate = `
/**
${pkg.name} - ${pkg.homepage}
Version: ${pkg.version}
Author: ${pkg.author}
*/
`
const isImage = extType => /png|jpe?g|svg|gif|tiff|bmp|ico/i.test(extType)
const getExtType = assetInfo => {
let [extType] = assetInfo.name.split('.').reverse()
if (isImage(extType)) {
extType = 'img'
}
return extType
}
const sharedConfig = {
server: {
open: true,
fs: {
strict: false,
},
},
define: {
'import.meta.env.enUS': JSON.stringify(enUS),
},
css: {
preprocessorOptions: {
scss: {
api: 'modern-compiler',
},
},
},
}
export default defineConfig({
...sharedConfig,
root: 'src/demo',
base: process.env.NODE_ENV === 'production' ? '/formeo/' : '/',
resolve: {
alias: {
formeo: resolve(__dirname, 'src/lib/js/index.js'),
},
},
build: {
emptyOutDir: true,
rollupOptions: {
input: {
demo: resolve(__dirname, 'src/demo/index.html'),
},
output: {
entryFileNames: 'assets/js/[name].min.js',
chunkFileNames: 'assets/js/[name].min.js',
assetFileNames: assetInfo => {
const extType = getExtType(assetInfo)
const ext = extType === 'img' ? '[ext]' : 'min.[ext]'
return `assets/${extType}/[name].${ext}`
},
},
external: ['formeo'],
},
outDir: resolve(__dirname, 'dist/demo'),
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
output: {
comments: false,
beautify: false,
},
},
},
plugins: [
createHtmlPlugin({
minify: true,
entry: 'js/index.js',
template: 'index.html',
filename: 'index.html',
inject: {
data: {
langFiles: languageFileOptions,
version: pkg.version,
},
},
}),
banner(bannerTemplate),
compression({
algorithm: 'gzip',
minRatio: 0.8,
ext: '.gz',
threshold: 10240,
}),
],
})