This repository has been archived by the owner on Jun 2, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
97 lines (93 loc) · 3.07 KB
/
rollup.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
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import sourceMaps from 'rollup-plugin-sourcemaps';
import {terser} from 'rollup-plugin-terser';
import pkg from './package.json';
export default [
{target: 'server', format: 'esm'},
{target: 'server', format: 'cjs'},
{target: 'browser', format: 'esm'},
].reduce((acc, {target, format}) => [
...acc,
...[
'development',
'production',
].map((environment) => ({
input: './src/index.js',
output: {
format,
sourcemap: true,
globals: {
'react': 'React',
'react-dom': 'ReactDOM',
'react-dom/server': 'ReactDOMServer',
},
file: [
'dist/isoreact-core',
target,
format,
environment === 'production' && 'min',
'js',
]
.filter(Boolean)
.join('.'),
},
plugins: [
sourceMaps(),
nodeResolve({
browser: target === 'browser',
preferBuiltins: target === 'server',
}),
babel({
babelrc: false,
presets: [
[
'@babel/preset-env',
{
modules: false,
targets: target === 'server ' ? {node: '10.0'} : {browsers: ['last 2 versions']},
},
],
'@babel/preset-react',
]
.filter(Boolean),
plugins: [
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-proposal-class-properties',
[
'babel-plugin-styled-components',
{
ssr: true,
displayName: true,
fileName: false,
},
],
environment === 'production' && 'babel-plugin-transform-react-remove-prop-types',
]
.filter(Boolean),
exclude: 'node_modules/**',
}),
commonjs(),
replace({
'process.browser': (target === 'browser').toString(),
'process.server': (target === 'server').toString(),
'process.env.NODE_ENV': `"${environment}"`,
}),
environment === 'production' && terser(),
]
.filter(Boolean),
external: [
// Top-level peerDependencies modules
...Object.keys(pkg.peerDependencies),
// Submodules of peerDependencies
'react-dom/server',
'rxjs/operators',
// Node modules
'crypto',
'os',
'util',
],
})),
], []);