-
Notifications
You must be signed in to change notification settings - Fork 3
/
vite.config.ts
79 lines (73 loc) · 1.95 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
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { resolve } from 'path';
import dts from 'vite-plugin-dts';
import { externalizeDeps } from 'vite-plugin-externalize-deps';
import eslint from 'vite-plugin-eslint';
import replace from '@rollup/plugin-replace';
const packageJson = require('./package.json');
/** Create banner */
const createBanner = () => {
return `/**!
* @nilfoundation/ui-kit v${packageJson.version}
*
* This source code is licensed under the MIT license found in the
* LICENSE.md file in the root directory of this source tree.
*
* @license MIT
*/`;
}
const packagesIncludeInStandalone = [
/baseui\/*/,
'lightweight-charts',
'@uiw/react-codemirror',
'@uiw/codemirror-themes',
'styletron-standard',
'styletron-react',
'copy-to-clipboard',
'inline-style-expand-shorthand',
'react/jsx-runtime',
];
export default defineConfig(({mode}) => {
const isStandalone = mode === 'standalone';
const plugins = [
react(),
eslint({include: ['./src/**/*.ts', './src/**/*.tsx']}),
externalizeDeps({except: isStandalone ? packagesIncludeInStandalone : []}),
];
if (!isStandalone) {
plugins.push(
dts({ staticImport: true, outputDir: './dist/.temp' }),
);
}
return ({
plugins: plugins,
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
formats: isStandalone ? ['iife'] : ['es', 'cjs'],
name: 'NilFoundationUIKit',
},
rollupOptions: {
output: {
banner: createBanner(),
sourcemap: true,
globals: isStandalone ? {
react: 'React',
'react-dom': 'ReactDOM',
} : undefined,
},
plugins: [
replace({
preventAssignment: true,
values: {
'process.env.NODE_ENV': JSON.stringify('production')
}
})
],
},
outDir: 'dist',
emptyOutDir: !isStandalone,
},
})
});