This repository has been archived by the owner on Jun 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
77 lines (72 loc) · 1.87 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
// @ts-check
import { terser } from 'rollup-plugin-terser';
import filesize from 'rollup-plugin-filesize';
import tslint from 'rollup-plugin-tslint';
import typescript from 'rollup-plugin-typescript2';
const isProd = !process.env.ROLLUP_WATCH;
const input = ['src/polling-observer.ts'];
const pluginFn = (format, minify) => {
return [
isProd && tslint({
throwError: true,
configuration: `tslint${isProd ? '.prod' : ''}.json`,
}),
typescript({
tsconfig: './tsconfig.json',
exclude: isProd ? ['src/(demo|test)/**/*'] : [],
...('umd' === format ? { tsconfigOverride: { compilerOptions: { target: 'es5' } } } : {}),
}),
isProd && minify && terser({
compress: true,
mangle: {
module: 'esm' === format,
properties: { regex: /^_/ },
reserved: ['PollingMeasure', 'PollingObserver'],
safari10: true,
toplevel: true,
},
output: { safari10: true },
safari10: true,
toplevel: true,
}),
isProd && filesize({ showBrotliSize: true }),
];
};
const multiBuild = [
{
file: 'dist/index.mjs',
format: 'esm',
exports: 'named',
},
{
file: 'dist/index.js',
format: 'cjs',
exports: 'named',
},
{
file: 'dist/polling-observer.umd.js',
format: 'umd',
name: 'PollingObserver',
exports: 'named',
},
{
file: 'dist/polling-observer.js',
format: 'esm',
},
].reduce((p, n) => {
const opts = [false, true].map(o => ({
input,
output: {
...n,
file: o ? n.file.replace(/(.+)(\.m?js)$/, '$1.min$2') : n.file,
sourcemap: true,
sourcemapExcludeSources: true,
},
experimentalOptimizeChunks: true,
plugins: pluginFn(n.format, o),
treeshake: { moduleSifeEffects: false },
...('umd' === n.format ? { context: 'window' } : {}),
}));
return (p.push(...opts), p);
}, []);
export default multiBuild;