-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvite.config.js
More file actions
52 lines (51 loc) · 1.88 KB
/
vite.config.js
File metadata and controls
52 lines (51 loc) · 1.88 KB
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
import { resolve } from 'path'
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
import replace from '@rollup/plugin-replace'
import copy from 'rollup-plugin-copy'
export default defineConfig(({ command, mode }) => {
if (mode !== 'production' || command === 'serve') {
return {
plugins: [react()],
server: {
port: process.env.PORT || 8080,
host: '0.0.0.0'
},
preview: {
port: process.env.PORT || 8080,
host: '0.0.0.0'
},
publicDir: 'public'
}
}
return {
plugins: [
react(),
cssInjectedByJsPlugin(),
replace({
'process.env.NODE_ENV': JSON.stringify(mode),
}),
// The `rollup-plugin-copy` plugin is not necessary if you are not need to run in `preview` mode, but I suggest to test in this mode for safe.
copy({
targets: [{
src: 'index.html',
dest: 'dist',
transform: (contents, filename) => contents.toString().replace('<script type="module" src="./src/main.js"></script>', '<script src="./main.js"></script><script>CMS.registerWidget("test", window.StarterControl, window.StarterPreview);</script>')
}],
hook: "writeBundle"
})
],
build: {
lib: {
entry: resolve(__dirname, 'src/main.js'),
name: 'main',
fileName: (format, entryName) => {
return format === 'iife' ? "main.js" : `main.${format}.js`
},
formats: ['iife'], // You can add other formats if you need.
},
sourcemap: true
}
}
})