-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
77 lines (69 loc) · 2.16 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
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import filesize from 'rollup-plugin-filesize';
import resolve from 'rollup-plugin-node-resolve';
import { uglify } from 'rollup-plugin-uglify';
import { checkPeerDependenciesForUmdBuild } from './dev/checkPeerDependenciesForUmdBuild';
import pkg from './package.json';
const input = 'src/index.ts';
const external = ['react'];
const extensions = ['.ts', '.tsx', '.js', '.jsx'];
const globals = {
react: 'React'
};
checkPeerDependenciesForUmdBuild(pkg.peerDependencies, external, globals);
// in CJS/ES the dependencies will added via your bundler so it is not necessary to add them to your bunlde.
const allExternals = external.concat(Object.keys(pkg.dependencies));
// If we only specify the external array, imports from submodules (`import '[PACKAGE]/lib/module'`) are not detected and added to your bundle
const checkIfModuleIsExternal = id =>
allExternals.filter(ext => id.substr(0, ext.length) === ext).length > 0;
const buildUMD = ({ isProduction = true }) => ({
input,
external,
output: {
name: 'ReactDynamicContext',
file: `dist/react-dynamic-context.umd${isProduction ? '.min' : ''}.js`,
format: 'umd',
sourcemap: true,
globals
},
plugins: [
resolve({ extensions }),
babel({ exclude: 'node_modules/**', runtimeHelpers: true, extensions }),
commonjs(),
isProduction && filesize(),
isProduction &&
uglify({
compress: {
keep_infinity: true,
pure_getters: true
},
warnings: true
})
]
});
const buildBundle = ({ isCommonjs = false }) => ({
input,
external: checkIfModuleIsExternal,
output: {
file: isCommonjs ? pkg.main : pkg.module,
format: isCommonjs ? 'cjs' : 'es',
sourcemap: true
},
plugins: [
resolve({ extensions }),
babel({
exclude: 'node_modules/**',
runtimeHelpers: true,
envName: isCommonjs ? 'commonjs' : process.env.NODE_ENV,
extensions
}),
filesize()
]
});
export default [
buildUMD({ isProduction: false }),
buildUMD({ isProduction: true }),
buildBundle({ isCommonjs: true }),
buildBundle({ isCommonjs: false })
];