-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
68 lines (62 loc) · 1.81 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
import fs from 'fs';
import path from 'path';
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react-swc';
import { tsAlias } from 'vite-plugin-ts-alias';
const pkgEntry = 'src/index.ts';
const uiEntry = 'src/ui.ts';
const iconsEntry = 'src/icons.tsx';
const rechartsEntry = 'src/recharts.ts';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
tsAlias(),
react(),
{
name: 'build-lib',
apply() {
return process.env.LIB === '1';
},
enforce: 'pre',
config() {
const commonCode = `// This file is auto generated by plugin.
import './styles/globals.css';`;
const pkgEntryCode = `${commonCode}\n${fs
.readdirSync('./src', 'utf-8')
.filter(
name =>
fs.statSync(path.resolve('src', name)).isDirectory() &&
/^[A-Z]/.test(name),
)
.map(name => `export * from './${name}';\n`)
.join('')}`;
const uiEntryCode = `${commonCode}\n${fs
.readdirSync('./src/ui', 'utf-8')
.map(name => `export * from './ui/${name}';\n`)
.join('')}`;
fs.writeFileSync(pkgEntry, pkgEntryCode, 'utf-8');
fs.writeFileSync(uiEntry, uiEntryCode, 'utf-8');
return {
build: {
lib: {
entry: {
index: pkgEntry,
ui: uiEntry,
icons: iconsEntry,
recharts: rechartsEntry,
},
formats: ['es'],
},
rollupOptions: {
external: ['react', 'react/jsx-runtime', 'react-dom'],
output: {
chunkFileNames: 'assets/[name]-[hash].js',
},
},
copyPublicDir: false,
},
};
},
},
],
});