-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrollup.config.js
103 lines (91 loc) · 2.24 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
const nodeResolve = require('rollup-plugin-node-resolve');
const replace = require('rollup-plugin-replace');
const commonjs = require('rollup-plugin-commonjs');
const json = require('rollup-plugin-json');
const { terser } = require('rollup-plugin-terser');
const sourceMaps = require('rollup-plugin-sourcemaps');
const globals = { react: 'React', 'react-native': 'ReactNative' };
const cjs = {
format: 'cjs',
sourcemap: true,
};
const esm = {
format: 'esm',
sourcemap: true,
};
const getCJS = override => ({ ...cjs, ...override });
const getESM = override => ({ ...esm, ...override });
const commonPlugins = [
sourceMaps(),
json(),
nodeResolve(),
commonjs({
namedExports: {
'react-is': ['isElement', 'isValidElementType', 'ForwardRef'],
},
}),
];
const standaloneBaseConfig = {
input: './src/targets/web/index.js',
output: {
file: 'dist/react-reduce-motion.js',
format: 'umd',
globals,
name: 'react-reduce-motion',
sourcemap: true,
},
external: Object.keys(globals),
plugins: commonPlugins,
};
const standaloneConfig = {
...standaloneBaseConfig,
plugins: standaloneBaseConfig.plugins.concat(
replace({
'process.env.NODE_ENV': JSON.stringify('development'),
})
),
};
const prodPlugins = [
replace({
'process.env.NODE_ENV': JSON.stringify('production'),
}),
terser({
sourcemap: true,
}),
];
const standaloneProdConfig = {
...standaloneBaseConfig,
output: {
...standaloneBaseConfig.output,
file: 'dist/react-reduce-motion.min.js',
},
plugins: standaloneBaseConfig.plugins.concat(prodPlugins),
};
const browserConfig = {
input: './src/targets/web/index.js',
output: [
getESM({ file: 'dist/react-reduce-motion.browser.esm.js' }),
getCJS({ file: 'dist/react-reduce-motion.browser.cjs.js' }),
],
external: Object.keys(globals),
plugins: commonPlugins,
};
const nativeConfig = {
input: './src/targets/native/index.js',
output: [
getCJS({
file: 'native/dist/react-reduce-motion.native.cjs.js',
}),
getESM({
file: 'native/dist/react-reduce-motion.native.esm.js',
}),
],
external: Object.keys(globals),
plugins: commonPlugins,
};
export default [
standaloneConfig,
standaloneProdConfig,
browserConfig,
nativeConfig,
];