-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
118 lines (108 loc) · 2.92 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
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import dts from 'vite-plugin-dts'
import dotenv from 'dotenv'
import pkg from './package.json'
import { resolve, dirname, basename, parse } from 'path'
import { libInjectCss } from 'vite-plugin-lib-inject-css'
import glob from 'glob'
import { viteStaticCopy } from 'vite-plugin-static-copy'
dotenv.config()
process.env['VITE_LIB_VERSION'] = pkg.version
export default defineConfig({
build: {
copyPublicDir: false,
lib: {
entry: {
main: resolve(__dirname, 'lib/main.ts'),
...getComponentsEntries(),
},
fileName: (format, entryName) => {
const isMainFile = entryName === 'main'
const isIconFile = entryName.startsWith('Icon') && entryName !== 'Icon'
if (isMainFile) return `main.${format}.js`
if (isIconFile) {
return `components/icons/${entryName}/index.${format}.js`
}
return `components/${entryName}/index.${format}.js`
},
name: 'aurora',
formats: ['es'],
},
cssCodeSplit: true,
rollupOptions: {
external: ['react', 'react-dom', 'react/jsx-runtime'],
output: {
assetFileNames: ({ name }) => {
const isCSS = name.endsWith('.css')
return isCSS && 'components/[name]/styles[extname]'
},
globals: {
react: 'React',
'react-dom': 'ReactDOM',
'react/jsx-runtime': 'react/jsx-runtime',
},
},
},
sourcemap: true,
minify: 'terser',
emptyOutDir: true,
},
resolve: {
alias: {
'@assets': '/lib/assets',
'@components': '/lib/components',
'@core': '/lib/core',
},
},
plugins: [
react(),
dts({ include: ['lib'], exclude: ['**/*.stories.tsx'] }),
libInjectCss(),
viteStaticCopy({
targets: [
{
src: [
'lib/core/styles/mixins.scss',
'lib/core/tokens/.cache/variables.scss',
],
dest: '.',
},
],
}),
],
css: {
preprocessorOptions: {
scss: {
additionalData: [
`
@import "lib/core/tokens/.cache/variables.scss";
@import "lib/core/styles/mixins.scss";
`,
],
},
},
},
})
function getComponentsEntries() {
const dir = 'lib/components'
const baseComponents = glob
.sync(`${dir}/**/*/index.tsx`)
.reduce((acc, filePath) => {
const folderPath = dirname(filePath)
const componentName = basename(folderPath)
return { ...acc, [componentName]: filePath }
}, {})
const iconComponents = glob
.sync(`${dir}/**/*/Icon*.tsx`)
.reduce((acc, filePath) => {
const { name: componentName } = parse(basename(filePath))
return { ...acc, [componentName]: filePath }
}, {})
const allComponents = {
...baseComponents,
...iconComponents,
}
console.log('components', baseComponents)
return allComponents
}