-
Notifications
You must be signed in to change notification settings - Fork 5
/
rollup.config.js
117 lines (106 loc) · 2.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
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
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import { terser } from 'rollup-plugin-terser';
import sourceMaps from "rollup-plugin-sourcemaps";
import pkg from './package.json';
const extensions = ['.js', '.mjs',];
const pkgname = pkg.name.replace(/^(@\S+\/)?(svelte-)?(\S+)/, '$3');
const clsname = pkgname.replace(/-\w/g, m => m[1].toUpperCase());
const external = [
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.peerDependencies || {}),
];
const appendMin = file => file.replace(/(\.[\w\d_-]+)$/i, '.min$1');
const replaceFilename = (file, name) => file.replace(/(.*)\/.*(\.[\w\d_-]+)/i, `$1/${name}$2`);
const pkgMain = replaceFilename(pkg.main, pkgname);
const pkgModule = replaceFilename(pkg.module, pkgname);
const input = 'src/index.js';
const files = {
npm: {
esm: { file: pkg.module, format: 'esm', },
umd: { file: pkg.main, format: 'umd', name: clsname, },
esmMin: {
file: appendMin(pkg.module),
format: 'esm',
sourcemap: true,
},
umdMin: {
file: appendMin(pkg.main),
format: 'umd',
sourcemap: true,
name: clsname,
},
},
cdn: {
esm: { file: pkgModule, format: 'esm', },
iife: { file: pkgMain, format: 'iife', name: clsname, },
esmMin: {
file: appendMin(pkgModule),
format: 'esm',
sourcemap: true,
},
iifeMin: {
file: appendMin(pkgMain),
format: 'iife',
sourcemap: true,
name: clsname,
},
}
};
const terserConfig = {
format: {
comments: false,
},
};
const cdnPlugins = [
resolve({ browser: true, extensions, }),
commonjs({ include: 'node_modules/**', extensions, }),
];
export default [{ // esm && umd bundles for npm/yarn
input,
output: [
files.npm.esm,
files.npm.umd,
],
external,
}, { // esm && umd bundles for npm/yarn (min)
input,
output: [
files.npm.esmMin,
files.npm.umdMin,
],
external,
plugins: [
sourceMaps(),
terser(terserConfig),
],
}, { // esm bundle for cdn/unpkg
input,
output: files.cdn.esm,
plugins: cdnPlugins,
}, { // iife bundle for cdn/unpkg
input,
output: files.cdn.iife,
plugins: [
...cdnPlugins,
babel({ babelHelpers: 'bundled' }),
],
}, { // esm bundle from cdn/unpkg (min)
input,
output: files.cdn.esmMin,
plugins: [
...cdnPlugins,
sourceMaps(),
terser(terserConfig),
],
}, { // iife bundle for cdn/unpkg (min)
input,
output: files.cdn.iifeMin,
plugins: [
...cdnPlugins,
sourceMaps(),
babel({ babelHelpers: 'bundled' }),
terser(terserConfig),
],
},];