This repository has been archived by the owner on May 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
70 lines (61 loc) · 2.17 KB
/
index.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
const path = require('path');
const merge = require('lodash.merge');
const babel = require('rollup-plugin-babel');
const babelrc = require('babelrc-rollup').default;
const babelHelpers = require('babel-helpers');
const commonjs = require('rollup-plugin-commonjs');
const resolve = require('rollup-plugin-node-resolve');
const progress = require('rollup-plugin-progress');
const uglify = require('rollup-plugin-uglify');
const cleanup = require('rollup-plugin-cleanup');
const json = require('rollup-plugin-json');
const { minify } = require('uglify-es');
const _suffixPath = (p, sffx) => {
const parts = path.parse(p);
parts.name = `${parts.name}.${sffx}`;
delete parts.base;
return path.format(parts);
};
const globalOptions = {
output: {
exports: 'named'
},
plugins: [
progress(),
babel(Object.assign(babelrc(), {
exclude: 'node_modules/**',
// NOTE: @see https://github.com/rollup/rollup/issues/1595
externalHelpersWhitelist: babelHelpers.list
.filter(helperName => helperName !== 'asyncGenerator')
})),
json({ indent: ' ' }),
resolve(),
commonjs(),
cleanup()
]
};
module.exports = function (baseOptions) {
baseOptions = Object.assign({ output: { file: null, name: null } }, baseOptions);
if (!baseOptions.output.file) {
throw new Error(`You must specify options.output.file`);
}
const configs = [];
const outputs = [
{ format: 'umd', file: baseOptions.output.file },
{ format: 'es', file: _suffixPath(baseOptions.output.file, 'es') }
];
outputs.forEach((output) => {
const options = merge({}, baseOptions, globalOptions, { output });
configs.push(options);
if (output.format !== 'umd') {
return;
}
const minOptions = merge({}, options, {
output: { file: _suffixPath(output.file, 'min') }
});
minOptions.plugins = minOptions.plugins.slice(0);
minOptions.plugins.push(uglify({}, minify));
configs.push(minOptions);
});
return configs;
};