-
Notifications
You must be signed in to change notification settings - Fork 24
/
rollup.config.js
95 lines (86 loc) · 2.32 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
91
92
93
94
95
import {readFile} from 'node:fs/promises';
import nodeResolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
// Remove these 2-lines to import JSON once with { type: 'json' } has official support. https://github.com/eslint/eslint/discussions/15305
const fileUrl = new URL('package.json', import.meta.url);
const pkg = JSON.parse(await readFile(fileUrl, 'utf8'));
const minifiedExtension = file => file.replace(/.js/, '.min.js');
const babelRuntimeVersion = pkg.dependencies['@babel/runtime'].replace(
/^\D*/,
'',
);
/**
* Used for generating external dependencies
* See: https://github.com/rollup/rollup-plugin-babel/issues/148#issuecomment-399696316
*/
const makeExternalPredicate = externalArray => {
if (externalArray.length === 0) {
return () => false;
}
const pattern = new RegExp(`^(${externalArray.join('|')})($|/)`);
return id => pattern.test(id);
};
const outputOptions = {
sourcemap: true,
banner: `/*! get-video-id v${pkg.version} | @license MIT © Michael Wuergler | https://github.com/radiovisual/get-video-id */`,
};
const config = {
input: './src/index.js',
output: [
{
file: pkg.main,
format: 'cjs',
...outputOptions,
},
{
file: minifiedExtension(pkg.main),
format: 'cjs',
plugins: [terser()],
...outputOptions,
},
{
file: pkg.module,
format: 'esm',
...outputOptions,
},
{
file: minifiedExtension(pkg.module),
format: 'esm',
plugins: [terser()],
...outputOptions,
},
{
file: minifiedExtension('dist/get-video-id.umd.js'),
format: 'umd',
name: 'getVideoId',
plugins: [terser()],
...outputOptions,
},
{
file: 'dist/get-video-id.umd.js',
format: 'umd',
name: 'getVideoId',
...outputOptions,
},
],
external: makeExternalPredicate([
// Handles both dependencies and peer dependencies so we don't have to manually maintain a list
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
]),
plugins: [
nodeResolve(),
commonjs(),
babel({
babelHelpers: 'runtime',
exclude: /node_modules/,
plugins: [
['@babel/plugin-transform-runtime', {version: babelRuntimeVersion}],
],
presets: [['@babel/preset-env', {targets: 'defaults'}]],
}),
],
};
export default config;