-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
89 lines (78 loc) · 2.37 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
import { defineConfig, UserConfig } from 'vite'
import react from '@vitejs/plugin-react'
import tsconfigPaths from 'vite-tsconfig-paths'
import alias from '@rollup/plugin-alias'
import dts from 'vite-plugin-dts'
import { libInjectCss } from 'vite-plugin-lib-inject-css'
import { extname, relative, resolve } from 'path'
import { fileURLToPath } from 'node:url'
import { glob } from 'glob'
// if(process.env.NODE_ENV === "development") {
console.log('⭐ process.env.BUILD_ENV:', process.env.BUILD_ENV)
const isBuildForStoryBook = process.env.BUILD_ENV === 'storybook'
const defaultPlugins = [alias(), react(), tsconfigPaths()]
const plugins = isBuildForStoryBook
? defaultPlugins
: [...defaultPlugins, libInjectCss(), dts({ include: ['lib'] })]
const config: UserConfig = {
plugins,
resolve: {
alias: {
'@': resolve(__dirname, 'lib'),
},
},
build: {
copyPublicDir: false,
lib: {
entry: resolve(__dirname, 'lib/main.ts'),
formats: ['es'],
},
rollupOptions: {
external: [
'react',
'react/jsx-runtime',
'@refinedev/antd',
'@refinedev/core',
'antd',
'antd-img-crop',
'axios',
'canvas-confetti',
'currency-symbol-map',
'jotai',
'lodash-es',
'nanoid',
'query-string',
'react-countdown',
'react-highlight-words',
'storybook',
'@storybook/builder-manager@7.4.6',
'@storybook/cli@7.4.6',
'@storybook/codemod@7.4.6',
'@storybook/core-server@7.4.6',
'@storybook/docs-mdx@0.1.0',
'@storybook/preview-api@7.4.6',
],
input: Object.fromEntries(
glob
.sync('lib/**/*.{ts,tsx}', { ignore: ['lib/**/*.stories.{ts,tsx}'] })
.map((file) => [
// The name of the entry point
// lib/nested/foo.ts becomes nested/foo
relative('lib', file.slice(0, file.length - extname(file).length)),
// The absolute path to the entry file
// lib/nested/foo.ts becomes /project/lib/nested/foo.ts
fileURLToPath(new URL(file, import.meta.url)),
]),
),
output: {
assetFileNames: 'assets/[name][extname]',
entryFileNames: '[name].js',
},
},
},
}
if (isBuildForStoryBook) {
delete config.build
}
// https://vitejs.dev/config/
export default defineConfig(config)