-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
80 lines (72 loc) · 1.93 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
// `rollup.config.js` adapted from the following sources
// https://hackernoon.com/building-and-publishing-a-module-with-typescript-and-rollup-js-faa778c85396
// https://github.com/alexjoverm/typescript-library-starter/blob/master/rollup.config.ts
// https://github.com/landakram/micromark-extension-wiki-link/blob/master/rollup.config.js
// package.json
// todo: upgrade rollup; use esm
// import pkg from './package.json' assert { type: 'json' };
import pkg from './package.json';
// rollup plugins
import ts from 'rollup-plugin-ts';
import commonjs from '@rollup/plugin-commonjs';
import { babel } from '@rollup/plugin-babel';
// configuration shared by esm / cjs / es
const shared = {
// dependencies will be installed by the consumer,
// so tell rollup not to bundle them with the package
external: [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
...Object.keys(pkg.devDependencies || {}),
],
};
// babel plugin
const babelPlugin = babel({
babelHelpers: 'runtime',
exclude: ['node_modules/**']
});
// esm-only configuration
const esm = {
...shared,
input: pkg.source,
output: [
{
file: pkg.browser,
format: 'esm',
sourcemap: true,
name: pkg.name,
banner: `// ${pkg.name} v${pkg.version} - ${pkg.repository.url}`,
}
],
plugins: [
ts({transpiler: 'babel'}),
commonjs(),
babelPlugin
],
};
// cjs/es-only configuration
const cjs_es = {
...shared,
input: pkg.source,
output: [
{
file: pkg.main,
format: 'cjs',
sourcemap: true,
// name: pkg.name,
banner: `// ${pkg.name} v${pkg.version} - ${pkg.repository.url}`,
},{
file: pkg.module,
format: 'es',
sourcemap: true,
// name: pkg.name,
banner: `// ${pkg.name} v${pkg.version} - ${pkg.repository.url}`,
}
],
plugins: [
ts({transpiler: 'babel'}),
commonjs(),
babelPlugin
]
};
export default [esm, cjs_es];