-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
90 lines (83 loc) · 2.39 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
import builtins from 'rollup-plugin-node-builtins';
import globals from 'rollup-plugin-node-globals';
import resolve from 'rollup-plugin-node-resolve';
import commonjs from 'rollup-plugin-commonjs';
import babel from 'rollup-plugin-babel';
import istanbul from 'rollup-plugin-istanbul';
import json from 'rollup-plugin-json';
import pkg from './package.json';
// Derive some of the configuration from package.json
const peerDependencies = Object.keys(pkg.peerDependencies || {});
const allExternals = peerDependencies.concat(
Object.keys(pkg.dependencies || {})).concat(
Object.keys(pkg.devDependencies || {}));
const commonPlugins = [
json(), // import json files as modules
babel({
exclude: 'node_modules/**',
externalHelpers: true
})
];
let targets = {
cjs: !process.env.TARGET || process.env.TARGET === 'cjs' || process.env.TARGET === 'all',
umd: !process.env.TARGET || process.env.TARGET === 'umd' || process.env.TARGET === 'all',
esm: !process.env.TARGET || process.env.TARGET === 'esm' || process.env.TARGET === 'all'
};
let sourcemap = process.env.SOURCEMAP === 'false' ? false
: process.env.SOURCEMAP === 'true' ? true : 'inline';
// Basic build formats, without minification
let builds = [];
if (targets.cjs) {
// CommonJS build for Node.js
builds.push({
input: 'src/main.js',
output: {
file: pkg.main,
format: 'cjs',
sourcemap
},
external: allExternals,
plugins: commonPlugins.concat(process.env.SOURCEMAP !== 'false' ? [istanbul()] : [])
});
}
if (targets.umd) {
// browser-friendly UMD build
builds.push({
input: 'src/module.js',
output: {
name: pkg.name,
file: pkg.browser,
format: 'umd',
globals: { 'd3': 'd3' },
sourcemap
},
plugins: [
resolve({
browser: true,
preferBuiltins: true
}), // so Rollup can find dependencies
commonjs(), // so Rollup can convert dependencies to ES modules
builtins(),
globals()
].concat(commonPlugins),
external: peerDependencies,
onwarn: message => {
if (/Circular dependency/.test(message)) return;
console.error(message);
}
});
}
if (targets.esm) {
// ES Module build for bundlers
builds.push({
input: 'src/module.js',
output: {
file: pkg.module,
format: 'es',
sourcemap
},
external: allExternals,
plugins: commonPlugins
});
}
export default builds;