-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
104 lines (92 loc) · 2.76 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
98
99
100
101
102
103
104
// @flow
//
// we invoke rollup twice (see package.json):
// once with NODE_ENV unset (defaulting to 'development'),
// once set to 'production'.
// for development, we build umd, cjs, es.
// for production, we build minimised umd.
// we replace NODE_ENV for umd only.
/* ::
type Warning = {
code: string,
message: string,
};
*/
import babel from 'rollup-plugin-babel';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import replace from 'rollup-plugin-replace';
import { uglify } from 'rollup-plugin-uglify';
import pkg from './package.json';
const NODE_ENV = process.env.NODE_ENV || 'development';
const PROD = NODE_ENV === 'production';
// used for the rollup builds: see .babelrc for the config used by jest.
const babelConfig = {
babelrc: false,
presets: [
[
'env',
{
targets: {
browsers: ['last 2 versions', 'safari >= 7'],
},
modules: false,
},
],
'react',
'flow',
],
plugins: [
'external-helpers',
'transform-object-rest-spread',
'transform-class-properties',
],
exclude: ['node_modules/**'],
};
const noThisIsUndefined = (warning /* : Warning */) => {
// hide an irritating warning that doesn't seem to affect functionality
// https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined
if (warning.code === 'THIS_IS_UNDEFINED') {
return;
}
console.error(warning.message); // eslint-disable-line no-console
};
export default [
{
input: 'src/index.jsx',
external: ['xstate', '@avaragado/xstateful', 'react', 'react-dom'],
output: [
{
file: PROD ? pkg.browser : pkg.browser.replace('.min.', '.'),
format: 'umd',
name: 'XStatefulReact',
globals: {
xstate: 'xstate',
'@avaragado/xstateful': 'XStateful',
react: 'React',
'react-dom': 'ReactDOM',
},
},
],
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify(NODE_ENV),
}),
babel(babelConfig),
resolve(),
commonjs(),
PROD && uglify(),
],
onwarn: noThisIsUndefined,
},
!PROD && {
input: 'src/index.jsx',
external: ['xstate', '@avaragado/xstateful', 'react', 'react-dom'],
output: [
{ file: pkg.main, format: 'cjs' },
{ file: pkg.module, format: 'es' },
],
plugins: [babel(babelConfig), resolve(), commonjs()],
onwarn: noThisIsUndefined,
},
].filter(Boolean);