-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathvite.config.ts
120 lines (118 loc) · 3.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
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
/*
* The AGPL License (AGPL)
* Copyright (c) 2022 hans000
*/
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import replace from '@rollup/plugin-replace';
import * as path from 'path'
import cdnImport from 'vite-plugin-cdn-import'
import { version, name } from './public/manifest.json'
const isLocal = !!process.env.VITE_LOCAL
const dist = name.toLowerCase().replace(' ', '-') + '-v' + version + (isLocal ? '-local' : '-cdn')
// https://vitejs.dev/config/
export default defineConfig({
css: {
preprocessorOptions: {
less: { javascriptEnabled: true }
}
},
build: {
outDir: path.join('dist', dist),
target: 'esnext',
rollupOptions: {
external: isLocal
? []
: [ 'react', 'react-dom' ]
}
},
plugins: [
react(),
!isLocal && cdnImport({
modules: [
{
name: 'react-is',
var: 'ReactIs',
path: [
'https://unpkg.com/[email protected]/umd/react-is.production.min.js',
],
},
{
name: 'prop-types',
var: 'PropTypes',
path: [
'https://unpkg.com/[email protected]/prop-types.min.js',
],
},
{
name: 'state-local',
var: 'state',
path: [
'https://unpkg.com/[email protected]/lib/umd/state-local.min.js'
]
},
{
name: 'dayjs',
var: 'dayjs',
path: [
'https://unpkg.com/[email protected]/dayjs.min.js',
],
},
{
name: 'react',
var: 'React',
path: [
'https://unpkg.com/[email protected]/umd/react.production.min.js',
],
},
{
name: 'react-dom',
var: 'ReactDOM',
path: [
'https://unpkg.com/[email protected]/umd/react-dom.production.min.js',
],
},
{
name: 'json-schema',
var: 'jsonSchema',
path: [
'https://unpkg.com/[email protected]/lib/validate.js',
],
},
{
name: '@ant-design/icons',
var: 'icons',
path: [
'https://unpkg.com/@ant-design/[email protected]/dist/index.umd.js',
],
},
{
name: 'antd',
var: 'antd',
path: [
'https://unpkg.com/[email protected]/dist/antd.min.js',
],
},
{
name: '@monaco-editor/loader',
var: 'monaco_loader',
path: [
'https://unpkg.com/@monaco-editor/[email protected]/lib/umd/monaco-loader.min.js',
],
},
{
name: '@monaco-editor/react',
var: 'monaco_react',
path: [
'https://unpkg.com/@monaco-editor/[email protected]/lib/umd/monaco-react.min.js',
]
},
]
}) as any,
replace({
preventAssignment: true,
'process.env.VITE_LOCAL': JSON.stringify(process.env.VITE_LOCAL),
'process.env.VITE_VS': JSON.stringify('https://unpkg.com/[email protected]/min/vs'),
}),
].filter(Boolean)
})