forked from developit/preact-redux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
86 lines (82 loc) · 1.97 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
import fs from 'fs';
import memory from 'rollup-plugin-memory';
import alias from 'rollup-plugin-alias';
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import babel from 'rollup-plugin-babel';
import es3 from 'rollup-plugin-es3';
const babelRc = JSON.parse(fs.readFileSync('.babelrc','utf8'));
const packageJson = require('./package.json');
babelRc.plugins.push('external-helpers');
const external = [
'redux',
'preact'
];
export default {
exports: 'default',
external: external,
useStrict: false,
globals: {
preact: 'preact',
redux: 'redux'
},
targets: [
{
dest: packageJson['main'],
format: 'umd',
moduleName: 'preactRedux',
sourceMap: true
},
{
dest: packageJson['jsnext:main'],
format: 'es',
sourceMap: true
}
],
plugins: [
memory({
path: 'src/index',
contents: "import * as lib from './index'; export default lib;"
}),
{
// 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'
}),
nodeResolve({
jsnext: true,
module: true,
skip: ['react', 'preact'],
preferBuiltins: false
}),
commonjs({
include: 'node_modules/**',
exclude: [ 'node_modules/react-redux/**']
}),
babel({
babelrc: false,
presets: [
['es2015', {
loose: true,
modules: false
}]
].concat(babelRc.presets.slice(1)),
plugins: babelRc.plugins
}),
replace({
'process.env.NODE_ENV': JSON.stringify('production')
}),
es3()
]
};