-
Notifications
You must be signed in to change notification settings - Fork 196
/
vite.config.js
137 lines (132 loc) · 3.13 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
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 { viteStaticCopy } from 'vite-plugin-static-copy'
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,
}),
viteStaticCopy({
targets: [
{
src: resolve('src/lib/icons/formeo-sprite.svg'),
dest: './assets/img/',
},
{
src: resolve('src/lib/icons/formeo-sprite.svg'),
dest: resolve('dist/'),
},
{
src: resolve('node_modules', '@draggable/formeo-languages/dist/lang/*'),
dest: './assets/lang',
},
{
src: resolve('dist/formeo.umd.js'),
dest: './assets/js/',
rename: 'formeo.min.js',
},
{
src: resolve('dist/formeo.umd.js'),
dest: resolve('dist/'),
rename: 'formeo.min.js',
},
{
src: resolve('dist/formeo.min.css'),
dest: './assets/css/',
},
],
}),
],
})