-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathvite.config.ts
87 lines (84 loc) · 2.31 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
import { resolve } from 'path'
import react from '@vitejs/plugin-react-swc'
import { visualizer } from 'rollup-plugin-visualizer'
import { defineConfig } from 'vite'
import { Plugin as importToCDN } from 'vite-plugin-cdn-import'
import cssInjectedByJsPlugin from 'vite-plugin-css-injected-by-js'
const lifecycle = process.env.npm_lifecycle_event
// https://vitejs.dev/config/
export default defineConfig({
base: './',
define: {
'process.env': {},
},
plugins: [
react(),
cssInjectedByJsPlugin(
lifecycle === 'docs'
? { topExecutionPriority: false }
: {
jsAssetsFilterFunction: function customJsAssetsfilterFunction(outputChunk) {
return (
outputChunk.fileName === 'index.mjs' ||
outputChunk.fileName === 'PlaygroundSandbox.mjs'
)
},
}
),
lifecycle === 'report'
? visualizer({ open: true, brotliSize: true, filename: 'report.html' })
: null,
lifecycle !== 'docs'
? null
: importToCDN({
modules: [
{
name: 'react',
var: 'React',
path: 'https://cdn.staticfile.org/react/18.2.0/umd/react.production.min.js',
},
{
name: 'react-dom',
var: 'ReactDOM',
path: 'https://cdn.staticfile.org/react-dom/18.2.0/umd/react-dom.production.min.js',
},
],
}),
],
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
},
},
},
resolve: {
alias: {
'@': resolve(__dirname, './src'),
},
},
optimizeDeps: {
exclude: lifecycle === 'dev' ? null : ['react', 'react-dom'],
},
build: {
minify: true,
outDir: lifecycle === 'docs' ? 'docs' : 'dist',
rollupOptions: {
external: ['react', 'react-dom'],
},
lib:
lifecycle === 'docs'
? undefined
: {
// Could also be a dictionary or array of multiple entry points
entry: [
resolve(__dirname, 'src/Playground/index.tsx'),
resolve(__dirname, 'src/Playground/PlaygroundSandbox.tsx'),
],
formats: ['es'],
fileName: (format, entryName) => {
return entryName + '.mjs'
},
},
},
})