-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrollup.config.mjs
206 lines (200 loc) · 5.13 KB
/
rollup.config.mjs
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import replace from '@rollup/plugin-replace';
import json from '@rollup/plugin-json';
import postcss from 'rollup-plugin-postcss';
import path from 'path';
import { fileURLToPath } from 'url';
import fs from 'fs';
import { cleandir } from 'rollup-plugin-cleandir';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const jsonRaw = fs.readFileSync(__dirname + '/package.json', { encoding: 'utf-8' });
const packageJson = JSON.parse(jsonRaw);
const rollupConfig = ({ framework }) => ({
input: `${framework}/index.js`,
external: [
'react',
'react-dom',
'prop-types',
/^@mantine/,
/@material-ui\/core\/.*/,
/^@mui/,
/^rsuite/,
/^antd/
],
output: [
{
banner: `/* LetsForm ${framework} v${packageJson.version} - UMD */`,
file: `dist/${framework}-umd/main.js`,
name: `lets-form/${framework}`,
/*globals: (id) => {
if (id === 'react') {
return 'React';
} else if (id == 'react-dom') {
return 'ReactDOM';
} else if (id === 'prop-types') {
return 'PropTypes';
}
return id;
},*/
format: 'umd',
// umd doesn't support dynamic imports in Rollup, bundle all together
inlineDynamicImports: true
},
{
banner: `/* LetsForm ${framework} v${packageJson.version} - ESM */`,
dir: `dist/${framework}-esm`,
name: `lets-form/${framework}`,
format: 'esm',
/*globals: (id) => {
if (id === 'react') {
return 'React';
} else if (id == 'react-dom') {
return 'ReactDOM';
} else if (id === 'prop-types') {
return 'PropTypes';
}
return id;
}*/
}
],
plugins: [
cleandir(),
json(),
postcss({
// avoid extracting into separate files, inject css into head
extract: false,
inject: true,
use: ['sass'],
}),
nodeResolve({
extensions: ['.js', '.jsx']
}),
babel({
babelHelpers: 'bundled',
presets: ['@babel/preset-react'],
extensions: ['.js', '.jsx']
}),
commonjs(),
replace({
preventAssignment: false
})
]
});
const rollupConfigUtils = () => ({
input: 'helpers/index-export.js',
external: [
'react',
'react-dom',
'prop-types',
/^@mantine/,
/@material-ui\/core\/.*/,
/^@mui/,
/^rsuite/,
/^antd/
],
output: [
{
banner: `/* LetsForm Utils v${packageJson.version} - UMD */`,
file: `dist/utils-umd/main.js`,
name: `lets-form/utils`,
format: 'umd',
// umd doesn't support dynamic imports in Rollup, bundle all together
inlineDynamicImports: true
},
{
banner: `/* LetsForm Utils v${packageJson.version} - ESM */`,
file: 'dist/utils-esm/index.js',
//dir: `dist/utils-esm`,
name: `lets-form/utils`,
format: 'esm'
}
],
plugins: [
cleandir(),
json(),
postcss({
// avoid extracting into separate files, inject css into head
extract: false,
inject: true,
use: ['sass'],
}),
nodeResolve({
extensions: ['.js', '.jsx']
}),
babel({
babelHelpers: 'bundled',
presets: ['@babel/preset-react'],
extensions: ['.js', '.jsx']
}),
commonjs(),
replace({
preventAssignment: false
})
]
});
export default () => {
console.log('Building version ', packageJson.version);
return [
rollupConfig({ framework: 'react-mantine' }),
rollupConfig({ framework: 'react-rsuite5' }),
rollupConfig({ framework: 'react' }),
rollupConfig({ framework: 'react-antd' }),
rollupConfig({ framework: 'react-material-ui' }),
rollupConfig({ framework: 'react-bootstrap' }),
{
input: `index.js`,
external: [
'react',
'react-dom',
'prop-types',
/^@mantine/,
/@material-ui\/core\/.*/,
/^@mui/,
/^rsuite/,
/^antd/
],
output: [
{
banner: `/* LetsForm Generator v${packageJson.version} - UMD */`,
file: `dist/generator-umd/main.js`,
name: `lets-form/generator`,
format: 'umd',
// umd doesn't support dynamic imports in Rollup, bundle all together
inlineDynamicImports: true
},
{
banner: `/* LetsForm Generator v${packageJson.version} - ESM */`,
dir: `dist/generator-esm`,
name: `lets-form/generator`,
format: 'esm'
}
],
plugins: [
cleandir(),
json(),
postcss({
// avoid extracting into separate files, inject css into head
extract: false,
inject: true,
use: ['sass'],
}),
nodeResolve({
extensions: ['.js', '.jsx']
}),
babel({
babelHelpers: 'bundled',
presets: ['@babel/preset-react'],
extensions: ['.js', '.jsx']
}),
commonjs(),
replace({
preventAssignment: false
})
]
},
rollupConfigUtils()
];
};