-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
94 lines (86 loc) · 2.23 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
/* global process */
/* eslint-disable no-console */
import resolve from '@rollup/plugin-node-resolve';
import cjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import strip from '@rollup/plugin-strip';
import terser from '@rollup/plugin-terser';
import glob from 'glob';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import PACKAGE from './package.json';
let extraPlugins = [];
// Map everything inside `src` to a format that rollup will accept as an
// `input` config value.
const mappings = Object.fromEntries(
glob.sync('src/**/*.js').map(file => {
let from = path.relative(
'src',
file.slice(0, file.length - path.extname(file).length)
);
let to = fileURLToPath(new URL(file, import.meta.url));
return [from, to];
})
);
if (!process.env.DEBUG) {
extraPlugins.push(
strip({
debugger: true,
functions: [
'console.debug',
'console.info',
'console.log',
'console.warn',
'console.group',
'console.groupCollapsed',
'console.groupEnd'
],
sourceMap: false
}),
terser()
);
}
export default [
// Browser-friendly UMD build.
{
input: 'src/all.js',
output: {
name: 'daub',
file: PACKAGE.browser,
format: 'umd'
},
plugins: [
resolve({ exportConditions: ['node'] }),
cjs(),
babel({
// The docs say to use 'runtime' here, that it removes duplication, but
// it caused a bunch of headaches and still made my files larger.
babelHelpers: 'bundled',
// Only transpile our source code.
exclude: 'node_modules/**',
}),
...extraPlugins
]
},
// Web worker UMD.
{
input: 'src/worker.js',
output: {
name: 'daub',
file: 'dist/daub.worker.umd.cjs',
format: 'umd'
},
plugins: [
resolve({ exportConditions: ['node'] }),
cjs(),
babel({
// The docs say to use 'runtime' here, that it removes duplication, but
// it caused a bunch of headaches and still made my files larger.
babelHelpers: 'bundled',
// Only transpile our source code.
exclude: 'node_modules/**',
}),
...extraPlugins
]
}
];