forked from jdf2e/nutui-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.build.ts
89 lines (86 loc) · 2.34 KB
/
vite.config.build.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
import { defineConfig } from 'vite'
import dts from 'vite-plugin-dts'
import fse from 'fs-extra'
import path from 'path'
import config from './package.json'
const banner = `/*!
* ${config.name} v${config.version} ${new Date()}
* (c) 2023 @jdf2e.
* Released under the MIT License.
*/`
const { resolve } = path
let fileStr = `@import "@/styles/variables.scss";`
const projectID = process.env.VITE_APP_PROJECT_ID
if (projectID) {
fileStr = `@import '@/styles/variables-${projectID}.scss';`
}
// https://vitejs.dev/config/
export default defineConfig({
define: {
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
},
resolve: {
alias: [{ find: '@', replacement: resolve(__dirname, './src') }],
},
plugins: [
dts({
outDir: 'dist/types',
clearPureImport: false,
exclude: [
'node_modules/**',
'src/sites/**',
'src/**/demo.tsx',
'src/**/demo.taro.tsx',
'src/**/*.spec.tsx',
],
beforeWriteFile(filePath, content) {
return { filePath: filePath.replace('src/', ''), content }
},
afterBuild: () => {
fse
.readFile('./dist/types/packages/nutui.react.build.d.ts', 'utf-8')
.then((data: string) => {
// fse.remove('./dist/types/packages/nutui.react.build.d.ts')
fse.outputFile(
'./dist/types/index.d.ts',
`${data.replace(/\.\//g, './packages/')}`
)
})
},
}),
],
build: {
minify: false,
emptyOutDir: true,
rollupOptions: {
// 请确保外部化那些你的库中不需要的依赖
external: ['react', 'react-dom'],
output: [
{
banner,
// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
globals: {
react: 'React',
'react-dom': 'ReactDOM',
},
format: 'es',
entryFileNames: 'nutui.react.es.js',
},
{
banner,
// 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
globals: {
react: 'React',
'react-dom': 'ReactDOM',
},
name: 'nutui',
format: 'umd',
entryFileNames: 'nutui.react.umd.js',
},
],
},
lib: {
entry: 'src/packages/nutui.react.build.ts',
},
},
})