This repository has been archived by the owner on Nov 6, 2021. It is now read-only.
forked from developit/preact-redux
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
75 lines (70 loc) · 2.06 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
import fs from 'fs';
import alias from 'rollup-plugin-alias';
import memory from 'rollup-plugin-memory';
import babel from 'rollup-plugin-babel';
import nodeResolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import replace from 'rollup-plugin-replace';
import es3 from 'rollup-plugin-es3';
const babelRc = JSON.parse(fs.readFileSync('.babelrc'));
let pkg = JSON.parse(fs.readFileSync('./package.json'));
let external = Object.keys(pkg.peerDependencies || {}).concat(Object.keys(pkg.dependencies || {}));
let format = process.env.FORMAT==='es' ? 'es' : 'umd';
babelRc.plugins.push('external-helpers');
export default {
entry: 'src/index.js',
sourceMap: true,
moduleName: pkg.amdName,
exports: format==='es' ? null : 'default',
dest: format==='es' ? pkg.module : pkg.main,
format,
external,
useStrict: false,
globals: {
'preact': 'preact',
'redux': 'Redux'
},
plugins: [
format==='umd' && memory({
path: 'src/index.js',
contents: "export { default } from './index';"
}),
{
// This insane thing transforms Lodash CommonJS modules to ESModules. Doing so shaves 500b (20%) off the library size.
load: function(id) {
if (id.match(/\blodash\b/)) {
return fs.readFileSync(id, 'utf8')
.replace(/\b(?:var\s+)?([\w$]+)\s*=\s*require\((['"])(.*?)\2\)\s*[,;]/g, 'import $1 from $2$3$2;')
.replace(/\bmodule\.exports\s*=\s*/, 'export default ');
}
}
},
alias({
'react-redux': 'node_modules/react-redux/src/index.js',
'react': __dirname+'/src/compat.js',
'invariant': __dirname+'/src/empty.js',
'prop-types': __dirname+'/src/prop-types.js'
}),
babel({
babelrc: false,
presets: [
['es2015', {
loose: true,
modules: false
}]
].concat(babelRc.presets.slice(1)),
plugins: babelRc.plugins
}),
nodeResolve({
jsnext: true,
main: true,
preferBuiltins: false
}),
commonjs({
include: ['node_modules/**'],
exclude: [ 'node_modules/react-redux/**']
}),
replace({ 'process.env.NODE_ENV': JSON.stringify('production') }),
es3()
].filter(Boolean)
};