forked from program-in-chinese/cnv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
105 lines (99 loc) · 2.51 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
105
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'
import { join } from 'path'
function resolver (path) {
return join(__dirname, path)
}
const babelrc = JSON.parse(fs.readFileSync('../../.babelrc'))
const modules = {
input: resolver('src/index.js'),
output: [
{
sourcemap: true,
name: 'NervRedux',
format: 'es',
file: resolver('dist/index.esm.js')
},
{
sourcemap: true,
format: 'cjs',
file: resolver('dist/index.js')
}
],
exports: 'default',
external: ['nervjs', 'redux'],
useStrict: false,
globals: {
nervjs: 'Nerv',
redux: 'Redux'
},
plugins: [
{
// 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': join(__dirname, 'node_modules/react-redux/src/index.js'),
react: 'nervjs',
invariant: join(__dirname, '/src/invariant.js'),
'prop-types': join(__dirname, '/src/prop-types.js')
}),
babel({
babelrc: false,
presets: [
[
'env',
{
// spec: true,
modules: false,
useBuiltIns: false,
loose: true
}
],
['stage-0']
],
plugins: babelrc.plugins.concat(['external-helpers'])
}),
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()
]
}
const umd = Object.assign({}, modules)
umd.output = {
format: 'umd',
sourcemap: true,
file: resolver('dist/nerv-redux.js'),
name: 'NervRedux'
}
umd.plugins = [
memory({
path: 'src/index.js',
contents: "export { default } from './index';"
})
].concat(modules.plugins)
export default [modules, umd]