-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrollup.config.react.js
67 lines (56 loc) · 1.69 KB
/
rollup.config.react.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
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import { terser } from 'rollup-plugin-terser';
const fs = require('fs')
const path = require('path')
function genReactConfig(size, minify) {
let inp = `index-${size}-react.js`
//ensure only the components specified are included.
var content = fs.readFileSync(inp, 'utf-8');
let components = []
content.replace(/from '(.*?)'/gmi, (match, fname) => {
components.push(path.resolve(__dirname, fname));
return ''
})
return {
input: inp,
output: {
format: 'esm',
name: 'app',
file: `public/build/bundle-react-${size}-${minify ? '-min' : '-nomin'}.js`
},
external: (id, parent, isResolved) => {
if (!id.startsWith('.')) return true;
if (id.includes('@babel/runtime')) return true;
let abs = path.resolve(path.dirname(parent), id)
return components.indexOf(abs) < 0;
},
plugins: [
babel({
babelHelpers: "runtime",
plugins:
["@babel/plugin-transform-runtime", "@babel/plugin-transform-react-jsx", "@babel/plugin-syntax-class-properties"]
}),
// If you have external dependencies installed from
// npm, you'll most likely need these plugins. In
// some cases you'll need additional configuration -
// consult the documentation for details:
// https://github.com/rollup/plugins/tree/master/packages/commonjs
resolve({
browser: true
}),
commonjs(),
minify && terser()
]
};
}
let configs = []
let reactSizes = [1,5,10,20,30,40,50]
reactSizes.forEach(size => {
configs = configs.concat([
genReactConfig(size, false),
genReactConfig(size, true),
]);
});
export default configs