This repository has been archived by the owner on Jun 22, 2021. It is now read-only.
/
rollup.config.js
84 lines (79 loc) · 1.89 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
import babel from 'rollup-plugin-babel';
import commonjs from 'rollup-plugin-commonjs';
import resolve from 'rollup-plugin-node-resolve';
import globals from 'rollup-plugin-node-globals';
import builtins from 'rollup-plugin-node-builtins';
import { terser } from 'rollup-plugin-terser';
import pkg from './package.json';
const name = 'WebId';
const prod = process.env.NODE_ENV === 'production';
const COPYRIGHT_YEAR = `2017-${parseInt((new Date()).getFullYear(), 10)}`;
const banner = formatStr => `/***
* ${name} v${pkg.version} (${pkg.homepage})${(formatStr) ? `
* ${formatStr}` : ''}
* Copyright ${COPYRIGHT_YEAR} ${pkg.author.name}
* Licensed under ${pkg.license}
***/`;
const terserOpts = {
output: {
comments(node, { value, type }) {
if (type === 'comment2') {
return /copyright/i.test(value);
}
return false;
},
},
};
export default [
{
input: 'src/webid.js',
external: ['assert', 'shortid', 'slugify'],
plugins: [
resolve(),
commonjs(),
babel({
babelrc: false,
// override targets to transpile for node 8
presets: [['airbnb', {
targets: { node: 8 },
}]],
runtimeHelpers: true,
}),
(prod) ? terser(terserOpts) : null,
],
output: {
file: pkg.main,
format: 'cjs',
sourcemap: !prod,
sourcemapFile: `${pkg.main}.map`,
banner: banner('Built for Node.js'),
},
},
{
input: 'src/webid.js',
// external: ['assert', 'shortid', 'slugify'],
plugins: [
globals(),
builtins(),
resolve({ preferBuiltins: true }),
commonjs(),
babel({
babelrc: false,
// override targets to transpile for node 8
presets: [['airbnb', {
targets: { node: 8 },
}]],
runtimeHelpers: true,
}),
(prod) ? terser(terserOpts) : null,
],
output: {
name,
file: pkg.browser,
format: 'umd',
sourcemap: !prod,
sourcemapFile: `${pkg.browser}.map`,
banner: banner('Built for the browser (UMD)'),
},
},
];