/
config.js
101 lines (95 loc) · 2.52 KB
/
config.js
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable @typescript-eslint/explicit-function-return-type */
const { babel } = require('@rollup/plugin-babel')
const commonjs = require('@rollup/plugin-commonjs')
const { nodeResolve: resolve } = require('@rollup/plugin-node-resolve')
const replace = require('@rollup/plugin-replace')
const json = require('@rollup/plugin-json')
const { terser } = require('rollup-plugin-terser')
const external = [
'react',
'react-dom',
'redux',
'react-redux',
'flat',
'react-router',
'react-router-dom',
'react-datepicker',
'styled-components',
'styled-system',
'prop-types',
'admin-bro',
'@admin-bro/design-system',
'admin-bro/property-types',
'admin-bro/types',
'admin-bro/style',
'axios',
'recharts',
'@carbon/icons-react',
'react-select/lib/Async',
'i18next',
'react-i18next',
]
const globals = {
react: 'React',
redux: 'Redux',
axios: 'axios',
flat: 'flat',
recharts: 'Recharts',
'react-select/lib/Async': 'ReactSelect',
'@carbon/icons-react': 'CarbonIcons',
'react-datepicker': 'ReactDatepicker',
'styled-components': 'styled',
'styled-system': 'StyledSystem',
'react-dom': 'ReactDOM',
'prop-types': 'PropTypes',
'react-redux': 'ReactRedux',
'react-router': 'ReactRouter',
'react-router-dom': 'ReactRouterDOM',
'admin-bro': 'AdminBro',
'@admin-bro/design-system': 'AdminBroDesignSystem',
'admin-bro/property-types': 'AdminBro.PropertyTypes',
'admin-bro/types': 'AdminBro.types',
'admin-bro/style': 'AdminBro.style',
i18next: 'i18n',
'react-i18next': 'ReactI18Next',
}
const extensions = ['.mjs', '.js', '.jsx', '.json', '.ts', '.tsx']
const plugins = ({ babelConfig = {}, commonJSConfig = {}, minify = false } = {}) => {
const pluginStack = [
resolve({
extensions,
mainFields: ['main', 'module'],
}),
json(),
replace({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV || 'development'),
'process.env.IS_BROWSER': 'true',
'process.env.': 'AdminBro.env.',
}),
commonjs({
...commonJSConfig,
}),
babel({
extensions,
babelrc: false,
babelHelpers: 'bundled',
exclude: 'node_modules/**/*.js',
presets: [
require.resolve('@babel/preset-react'),
require.resolve('@babel/preset-env'),
require.resolve('@babel/preset-typescript'),
],
...babelConfig,
}),
]
if (minify) {
pluginStack.push(terser())
}
return pluginStack
}
module.exports = {
external,
globals,
plugins,
}