forked from ncihtan/htan-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.lib.config.ts
68 lines (66 loc) · 2.27 KB
/
vite.lib.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 react from '@vitejs/plugin-react';
import path from 'path';
import { Plugin } from 'vite';
import dts from 'vite-plugin-dts';
import { externals } from 'rollup-plugin-node-externals';
export function nodeExternals(): Plugin {
return {
enforce: 'pre',
...externals({
// Workaround for problematic dependencies when defined as external.
// we have to bundle these dependencies together with the library (exclude from being external)
exclude: ['react-spinners'],
}),
};
}
export function getConfig(dirName: string, libName: string) {
return {
plugins: [
nodeExternals(),
react({
// seems like classic runtime is needed for react versions prior to 18
// we may want to remove 'jsxRuntime' option when we upgrade all our projects to react 18+
jsxRuntime: 'classic',
babel: {
parserOpts: {
plugins: ['decorators-legacy', 'classProperties'],
},
},
}),
dts({
insertTypesEntry: true,
}),
],
build: {
lib: {
entry: path.resolve(dirName, 'src/index.ts'),
name: libName,
formats: ['es', 'cjs'],
fileName: (format: string) => `index.${format}.js`,
},
rollupOptions: {
external: [
'mobx',
'mobx-react',
'path',
'react',
'react-dom',
'styled-components',
// treat any @htan package as external to avoid redundant bundling
/^@htan*/,
// this is a workaround, nodeExternals cannot identify victory modules as external
/^victory*/,
],
output: {
globals: {
jquery: '$',
lodash: '_',
react: 'React',
'react-dom': 'ReactDOM',
'styled-components': 'styled',
},
},
},
},
};
}