-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.mts
108 lines (100 loc) · 3.04 KB
/
vite.config.mts
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
/* eslint-disable import/no-unresolved */
/* eslint-disable import/no-extraneous-dependencies */
// eslint-disable-next-line unused-imports/no-unused-imports
import react from '@vitejs/plugin-react'
import reactSwc from '@vitejs/plugin-react-swc'
import dotenv from 'dotenv'
import { visualizer } from 'rollup-plugin-visualizer'
import Unocss from 'unocss/vite'
import { defineConfig, type ConfigEnv, type PluginOption } from 'vite'
import importer from 'vite-plugin-importer'
import monkey, { cdn } from 'vite-plugin-monkey'
import tsconfigPaths from 'vite-tsconfig-paths'
import packageJson from './package.json'
dotenv.config()
function createReactPlugin(command: ConfigEnv['command']) {
const swc = reactSwc()
const babel = react()
// return babel
// use @vitejs/plugin-react in build
// for use emotion babel plugin
// https://emotion.sh/docs/babel#features-which-are-enabled-with-the-babel-plugin
return command === 'serve' ? swc : babel
}
function createImportPlugins(command: ConfigEnv['command']): PluginOption[] {
return [
command === 'build' &&
importer({
libraryName: '@icon-park/react',
libraryDirectory: 'es/icons',
camel2DashComponentName: false // default: true,
})
].filter(Boolean)
}
// https://vitejs.dev/config/
export default defineConfig(({ command }) => ({
// https://github.com/lisonge/vite-plugin-monkey/issues/10#issuecomment-1207264978
esbuild: {
charset: 'utf8'
},
plugins: [
tsconfigPaths(),
Unocss(),
createReactPlugin(command),
...createImportPlugins(command),
monkey({
entry: 'src/main.tsx',
userscript: {
name: {
'': packageJson.title,
'zh-CN': packageJson['title:zh-CN'],
'zh-TW': packageJson['title:zh-TW']
},
author: packageJson.author,
namespace: packageJson.author,
description: {
'': packageJson.description,
'zh-CN': packageJson['description:zh-CN'],
'zh-TW': packageJson['description:zh-TW']
},
license: packageJson.license,
match: [
// all
'*://*/*'
],
icon: 'https://chat.openai.com/favicon.ico',
'run-at': 'document-end'
},
build: {
fileName: 'smart-web.user.js',
externalGlobals: {
react: cdn.npmmirror('React', 'umd/react.production.min.js'),
'react-dom': cdn.npmmirror(
'ReactDOM',
'umd/react-dom.production.min.js'
),
i18next: cdn.npmmirror('i18next', 'dist/umd/i18next.min.js'),
'react-draggable': cdn.npmmirror(
'ReactDraggable',
'build/web/react-draggable.min.js'
),
'zustand/middleware': cdn.npmmirror(
'zustandMiddleware',
'umd/middleware.production.js'
)
}
},
server: {
open: true
}
}),
process.env.NODE_ENV === 'production' &&
process.argv.includes('--analyze') &&
visualizer({
open: true
})
],
build: {
cssMinify: false
}
}))