-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.lib.ts
More file actions
70 lines (66 loc) · 2.09 KB
/
Copy pathvite.config.lib.ts
File metadata and controls
70 lines (66 loc) · 2.09 KB
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
import type { OutputOptions } from 'rollup';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
// lite tools
const lightweightTools = ['clsx', 'cssmix', 'date-fns'];
// https://vitejs.dev/config/
export default defineConfig({
build: {
copyPublicDir: false,
cssCodeSplit: true,
lib: {
entry: resolve(__dirname, 'lib/main.ts'),
name: 'BRL',
},
outDir: 'dist-lib',
rollupOptions: {
external: ['react', 'react/jsx-runtime', 'react-dom'],
output: ['es', 'cjs'].map((format) => ({
chunkFileNames: format === 'cjs' ? '[name].cjs' : '[name].js',
format,
globals: {
react: 'React',
'react-dom': 'ReactDom',
'react/jsx-runtime': 'ReactJsxRuntime',
},
manualChunks(id) {
if (id.includes('node_modules')) {
if (lightweightTools.some((tool) => id.includes(`${tool}/`))) {
return 'lite';
}
return 'vendor';
}
if (id.includes('lib/')) {
const parts = id.split('lib/')[1].split('/');
const fileName = parts[parts.length - 1].replace(/\.[^/.]+$/, '');
if (fileName !== 'index') {
return parts.length > 1 ? `${parts[0]}/${fileName}` : fileName;
}
}
},
})) as OutputOptions[],
},
},
css: {
modules: {
localsConvention: 'camelCase',
},
},
plugins: [react(), dts({ tsconfigPath: './tsconfig.lib.json' })],
resolve: {
alias: {
'@assets': resolve(__dirname, 'lib/assets'),
'@components': resolve(__dirname, 'lib/components'),
'@contexts': resolve(__dirname, 'lib/contexts'),
'@hocs': resolve(__dirname, 'lib/hocs'),
'@hooks': resolve(__dirname, 'lib/hooks'),
'@lib': resolve(__dirname, 'lib'),
'@pages': resolve(__dirname, 'lib/pages'),
'@store': resolve(__dirname, 'lib/store'),
'@tools': resolve(__dirname, 'lib/tools'),
'@types': resolve(__dirname, 'lib/types'),
},
},
});