-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
89 lines (79 loc) · 1.94 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
const rollup = require('rollup').rollup;
const buble = require('rollup-plugin-buble');
const uglify = require('rollup-plugin-uglify');
const filesize = require('rollup-plugin-filesize');
const replace = require('rollup-plugin-replace');
const nodeResolve = require('rollup-plugin-node-resolve');
const p = require('path');
const pack = require('./package.json');
function withNodeResolve(arr, resolveConfig) {
const newArray = Array.from(arr);
const index = newArray.findIndex(plugin => plugin.name === 'buble');
newArray.splice(index + 1, 0, nodeResolve(resolveConfig));
return newArray
}
let plugins = [
buble({
objectAssign: 'Object.assign'
})
];
if (process.env.NODE_ENV === 'production') {
plugins.push(
uglify({
warnings: false,
compress: {
screw_ie8: true,
dead_code: true,
unused: true,
drop_debugger: true,
booleans: true
},
mangle: {
screw_ie8: true
}
})
);
plugins.push(
replace({
VERSION: pack.version,
'process.env.NODE_ENV': JSON.stringify('production')
})
)
} else {
plugins.push(
replace({
VERSION: pack.version,
})
)
}
plugins.push(filesize());
function createBundle(path) {
const copyright =
'/*!\n' +
' * fragment-node v' + pack.version + '\n' +
' * (c) ' + new Date().getFullYear() + ' ' + pack.author.name + '\n' +
' * Released under the ' + pack.license + ' License.\n' +
' */';
const entry = p.resolve('src/index.js');
const dest = p.resolve(`dist/fragment-node.${ process.env.NODE_ENV === 'production' ? 'min.js' : 'js' }`);
const bundleConfig = {
dest,
format: 'umd',
moduleName: 'FragmentNode',
globals: {
moduleGlobal: 'FragmentNode'
},
banner: copyright,
sourceMap: false
};
// Skip bundling dependencies of each package
plugins = withNodeResolve(plugins, {
module: true,
jsnext: true,
main: true
});
return rollup({ entry, plugins }).then(({ write }) => write(bundleConfig)).catch(err => {
console.log(err)
});
}
createBundle();