forked from ramp4-pcar4/ramp4-pcar4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
161 lines (150 loc) · 4.56 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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import { defineConfig, mergeConfig } from 'vite';
import mkcert from 'vite-plugin-mkcert';
import vue from '@vitejs/plugin-vue';
import VitePluginI18n from './scripts/vite-plugin-i18n';
import VitePluginVersion from './scripts/vite-plugin-version';
import { resolve } from 'path';
import pkg from './package.json';
const distName = resolve(__dirname, process.env.DIST_NAME || 'dist');
const baseConfig = {
plugins: [vue(), VitePluginI18n(), VitePluginVersion(), mkcert()],
define: {
'process.env': process.env
},
base: './',
resolve: {
alias: {
'@': resolve(__dirname, 'src'),
vue: 'vue/dist/vue.esm-bundler.js'
}
},
build: {
copyPublicDir: false,
target: 'esnext',
emptyOutDir: false,
outDir: distName,
cssMinify: false,
minify: false,
lib: {
entry: resolve(__dirname, 'src/main.ts'),
name: 'RAMP'
},
rollupOptions: {
output: {
inlineDynamicImports: true,
assetFileNames: (assetInfo: any) => {
return assetInfo.name === 'style.css' ? 'bad.css' : assetInfo.name;
}
}
}
},
server: {
open: '/demos/enhanced-samples.html',
https: true
}
} as Record<string, any>;
function inlineConfig() {
return mergeConfig(baseConfig, {
build: {
cssMinify: true,
minify: true,
sourcemap: true,
lib: {
fileName: (format: string) => `ramp.browser.${format}.js`,
formats: ['es', 'iife']
},
rollupOptions: {
output: {
assetFileNames: (assetInfo: any) => {
return assetInfo.name === 'style.css' ? 'ramp.css' : assetInfo.name;
}
}
}
}
});
}
function esDynamicConfig() {
return mergeConfig(baseConfig, {
build: {
outDir: `${distName}/esDynamic`,
minify: true,
sourcemap: true,
cssMinify: true,
lib: {
fileName: `ramp`,
formats: ['es']
},
rollupOptions: {
output: {
inlineDynamicImports: false,
assetFileNames: (assetInfo: any) => {
return assetInfo.name === 'style.css' ? 'ramp.css' : assetInfo.name;
}
}
}
},
esbuild: { legalComments: 'none' }
});
}
function npmBundleConfig() {
const externalImports = Object.keys(pkg.dependencies).map(dep => new RegExp(`^${dep}`));
const config = mergeConfig(baseConfig, {
build: {
lib: {
fileName: 'ramp.bundle.es',
formats: ['es']
},
rollupOptions: {
external: externalImports
}
}
});
return config;
}
function testBuildConfig() {
delete baseConfig.build.rollupOptions;
delete baseConfig.build.lib;
const config = mergeConfig(baseConfig, {
publicDir: false,
root: 'demos',
build: {
outDir: `${distName}/demos`,
rollupOptions: {
input: {
main: '/index.html',
multi: '/index-multi.html',
e2e: '/index-e2e.html',
wet: '/index-wet.html',
enhancedSamples: '/enhanced-samples.html',
enhancedAll: '/enhanced-all.html',
samples: '/index-samples.html',
all: '/index-all.html',
qaSamples: '/qa-samples.html',
qaAll: '/qa-all.html',
form: '/index-form.html',
teleport: '/index-teleport.html',
teleportWet: '/index-teleport-wet.html',
teleportDetails: '/index-teleport-details.html',
multiWet: '/index-multi-wet.html'
}
}
}
});
return config;
}
export default defineConfig(viteConfig => {
const { command, mode } = viteConfig;
if (command === 'build') {
if (mode === 'npm') {
return npmBundleConfig();
} else if (mode === 'esDynamic') {
return esDynamicConfig();
} else if (mode === 'inline') {
return inlineConfig();
} else {
return testBuildConfig();
}
} else {
return baseConfig;
}
});