-
Notifications
You must be signed in to change notification settings - Fork 27
/
rollup.config.prod.ts
58 lines (53 loc) · 1.99 KB
/
rollup.config.prod.ts
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
import { readFileSync } from 'fs';
import { RollupOptions, ModuleFormat } from "rollup";
import typescript from '@rollup/plugin-typescript';
import terser from '@rollup/plugin-terser';
import commonjs from '@rollup/plugin-commonjs';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { dts } from "rollup-plugin-dts";
import { visualizer } from 'rollup-plugin-visualizer';
const pkg = JSON.parse(readFileSync('package.json').toString());
interface BundleOptions {
minimize?: boolean,
resolve?: boolean,
types?: boolean,
stats?: boolean,
}
export function bundle(format: ModuleFormat, filename: string, options: BundleOptions = {}): RollupOptions {
return {
input: 'src/index.ts',
output: {
file: filename,
format: format,
banner: `/*! ${pkg.name} ${pkg.version} - (c) ${pkg.author} - ${pkg.homepage} */`,
name: pkg.name,
sourcemap: false,
globals: {
leaflet: 'L',
},
},
external: [
...(pkg.peerDependencies ? Object.keys(pkg.peerDependencies) : []), // always exclude peerDependencies
...(options.resolve ? [] : (pkg.dependencies ? Object.keys(pkg.dependencies) : [])), // exclude dependencies, if resolve is not required
],
plugins: [
...(options.resolve ? [nodeResolve()] : []),
commonjs(),
typescript(),
...(options.minimize ? [terser()] : []),
...(options.types ? [dts()] : []),
...(options.stats ? [
visualizer({
filename: filename + '.stats.html',
template: "treemap"
})] : []),
]
};
}
export default [
bundle('cjs', pkg.main),
bundle('esm', pkg.module),
bundle("umd", pkg.browser.replace('.min', ''), { resolve: true, stats: true }),
bundle("umd", pkg.browser, { resolve: true, minimize: true }),
bundle("es", pkg.types, { types: true }),
];