-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.lib.js
87 lines (81 loc) · 1.97 KB
/
vite.config.lib.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
import path from 'path'
import { defineConfig } from 'vite'
import reactPlugin from '@vitejs/plugin-react'
import tsconfigPaths from 'vite-tsconfig-paths'
import replace from 'rollup-plugin-replace'
import { replaceCodePlugin } from 'vite-plugin-replace'
import externalGlobals from 'rollup-plugin-external-globals'
import pckg from './package.json'
import { minifyEs } from './vite.plugins'
const NODE_ENV = process.env.NODE_ENV || 'production'
export default defineConfig({
plugins: [
tsconfigPaths(),
reactPlugin(),
replaceCodePlugin({
replacements: [
{
from: /CMF_APP_VERSION/g,
to: pckg.version,
},
{
from: /CMF_APP/g,
to: pckg.name,
},
],
}),
minifyEs(),
],
server: {
port: 2000,
hot: true,
},
esbuild: {
drop: ['console', 'debugger'],
},
build: {
minify: 'terser',
assetsInlineLimit: 0,
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
lib: {
entry: path.resolve(__dirname, 'src/main-lib.tsx'),
name: 'bundle',
formats: ['es', 'umd', 'esm'],
fileName: (format) => {
if (format === 'es') {
return 'bundle-lib.js'
}
if (format === 'esm') {
return 'bundle-lib.min.js'
}
return `bundle-lib.${format}.js`
},
},
sourcemap: false,
rollupOptions: {
input: 'src/main-lib.tsx',
preserveEntrySignatures: true,
output: {
dir: 'dist/runtime-lib-bundle',
assetFileNames: 'bundle-lib.css',
chunkFileNames: 'chunk-[name].js',
preserveModules: false,
},
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
}),
externalGlobals({
react: 'window.React',
'react-dom': 'window.ReactDOM',
'react-dom/client': 'window.ReactDOM.client',
}),
],
},
},
})