-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
rollup.config.js
134 lines (129 loc) · 3.11 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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { globSync } from 'glob';
import typescript from '@rollup/plugin-typescript';
import json from '@rollup/plugin-json';
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { getBabelOutputPlugin } from '@rollup/plugin-babel';
import replace from '@rollup/plugin-replace';
import terser from '@rollup/plugin-terser';
const supportedNodeVersion = '18.0.0';
const inputs = globSync('src/**/*.ts', {
ignore: ['**/__mocks__/**', '**/__tests__/**', '**/mocks/**', '**/*.test.ts', '**/*.d.ts'],
});
const external = (id) => !/^(\.|\/|[a-z]:\\)/i.test(id);
const umdName = 'hibp';
const replaceOpts = {
'process.env.NODE_ENV': JSON.stringify('production'),
preventAssignment: true,
};
const typescriptOpts = {
exclude: ['**/*.d.ts', 'playwright/**'],
declaration: false,
};
const nodeResolveOpts = {
browser: true,
};
const terserOpts = {
compress: {
pure_getters: true,
unsafe: true,
unsafe_comps: true,
},
};
export default [
// CommonJS
{
input: inputs,
output: {
dir: 'dist/cjs',
entryFileNames: '[name].cjs',
format: 'cjs',
sourcemap: true,
indent: false,
preserveModules: true,
preserveModulesRoot: 'src',
},
external,
plugins: [
json({ preferConst: true }),
typescript(typescriptOpts),
getBabelOutputPlugin({
plugins: ['babel-plugin-annotate-pure-calls'],
presets: [['@babel/env', { targets: { node: supportedNodeVersion } }]],
}),
],
},
// ESM for Bundlers
{
input: inputs,
output: {
dir: 'dist/esm',
format: 'esm',
sourcemap: true,
indent: false,
preserveModules: true,
preserveModulesRoot: 'src',
},
external,
plugins: [
json({ preferConst: true }),
typescript(typescriptOpts),
getBabelOutputPlugin({
plugins: ['babel-plugin-annotate-pure-calls'],
presets: [['@babel/env', { targets: { node: supportedNodeVersion } }]],
}),
],
},
// ESM for Browsers
{
input: 'src/hibp.ts',
output: {
file: 'dist/browser/hibp.module.js',
format: 'esm',
sourcemap: true,
indent: false,
inlineDynamicImports: true,
},
plugins: [
json({ preferConst: true }),
nodeResolve(nodeResolveOpts),
commonjs(),
replace(replaceOpts),
typescript(typescriptOpts),
terser(terserOpts),
],
},
// UMD
{
input: 'src/hibp.ts',
output: {
file: 'dist/browser/hibp.umd.js',
format: 'esm',
sourcemap: true,
indent: false,
inlineDynamicImports: true,
},
plugins: [
json({ preferConst: true }),
nodeResolve(nodeResolveOpts),
commonjs(),
replace(replaceOpts),
typescript(typescriptOpts),
getBabelOutputPlugin({
moduleId: umdName,
presets: [
[
'@babel/env',
{
modules: 'umd',
targets: {
browsers: ['defaults', 'supports promises'],
},
},
],
],
}),
terser(terserOpts),
],
},
];