forked from tlentz/vite-ts-webcomps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
50 lines (48 loc) · 1.07 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
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
// https://vitejs.dev/config/
// @ts-ignore
export default defineConfig((env) => {
const isDev = env.mode === 'development';
const isProd = env.mode === 'production';
const port = process.env.PORT || 3469;
const webcompname = process.env.WEBCOMPNAME || null;
console.log({
isDev,
isProd,
port,
webcompname,
});
if (!webcompname && isProd) {
console.error('WEBCOMPNAME is required in production mode');
return process.exit(0);
}
return {
define: {
'process.env': {},
},
plugins: [react()],
build: {
outDir: 'dist',
emptyOutDir: true,
lib: {
entry: `src/${webcompname}/index.tsx`,
formats: ['iife'],
name: `${webcompname}.js`,
},
rollupOptions: {
output: {
format: 'iife',
entryFileNames: `${webcompname}.js`,
},
},
cssCodeSplit: true,
minify: true,
},
server: {
host: 'localhost',
port,
cors: true,
},
};
});