-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
74 lines (68 loc) · 1.87 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
import { resolve } from 'path';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import react from '@vitejs/plugin-react';
import { viteStaticCopy } from 'vite-plugin-static-copy';
// tsconfg 설정 인식이 잘 안됨. 설정파일이라서 그냥 무시하도록 설정
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import packageJson from './package.json';
export default defineConfig({
build: {
lib: {
entry: convertExportsToEntries(packageJson.exports),
name: 'cds',
fileName: 'index',
},
sourcemap: true,
emptyOutDir: true,
rollupOptions: {
external: [
'react',
'react-dom',
'@emotion/react',
'@emotion/styled',
'@emotion/react/jsx-runtime',
],
output: [
{
format: 'cjs',
preserveModulesRoot: 'src',
entryFileNames: '[name].js',
},
{
format: 'es',
preserveModules: true,
preserveModulesRoot: 'src',
entryFileNames: '[name].mjs',
},
],
},
},
plugins: [
react({
jsxImportSource: '@emotion/react',
jsxRuntime: 'automatic',
}),
dts({ tsconfigPath: './tsconfig.build.json' }),
viteStaticCopy({
targets: [
{
src: ['src/*.css'],
dest: resolve(__dirname, 'dist'),
},
],
}),
],
});
function convertExportsToEntries(exports: object) {
const entries: Record<string, string> = {};
for (const key in exports) {
// Ignore regular expression patterns that end with *.*
if (/^\.\S+[^/]+\.[^/]+$/.test(key)) continue;
const entryPath = key === '.' ? './src/index.ts' : `src/${key}/index.ts`;
const formattedKey = key === '.' ? 'index' : `${key.slice(2)}/index`;
entries[formattedKey] = resolve(__dirname, entryPath);
}
return entries;
}