-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollup.config.js
71 lines (61 loc) · 1.66 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
const fs = require('fs');
const path = require('path');
const babel = require('rollup-plugin-babel');
import {uglify} from 'rollup-plugin-uglify';
const license = require('rollup-plugin-license');
const {name} = require('./package.json');
const base = __dirname;
const src = path.resolve(base, 'src');
const dist = path.resolve(base, 'dist');
// Ensure dist directory exists
if (!fs.existsSync(dist)) {
fs.mkdirSync(dist)
}
function defaultPlugins() {
return [
babel({
plugins: ['external-helpers']
}),
uglify({
sourcemap: true,
// numWorkers: 1,
}),
license({
// sourceMap: true,
// cwd: '.', // Default is process.cwd()
banner: `<%= pkg.name %> v<%= pkg.version %>
(c) <%= moment().format('YYYY') %> <%= pkg.author %>
Released under the <%= pkg.license %> License.`,
}),
]
}
let plugins = defaultPlugins();
plugins.splice(1, 1);
let productionPlugins = defaultPlugins();
let configs = [
{
input: path.resolve(src, 'index.js'),
// external: Object.keys(dependencies),
plugins,
output: {
format: 'iife',
file: path.resolve(dist, name + '.js'),
sourcemap: true
},
}
];
if (process.env.NODE_ENV === 'production') {
let newConfigs = [
{
input: path.resolve(src, 'index.js'),
plugins: productionPlugins,
output: {
format: 'iife',
file: path.resolve(dist, name + '.min.js'),
sourcemap: true
},
}
];
configs.push(...newConfigs);
}
module.exports = configs;