-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrollup.config.mjs
More file actions
101 lines (91 loc) · 2.81 KB
/
rollup.config.mjs
File metadata and controls
101 lines (91 loc) · 2.81 KB
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
import nodeResolve from '@rollup/plugin-node-resolve';
import autoExternal from 'rollup-plugin-auto-external';
import bundleSize from 'rollup-plugin-bundle-size';
import terser from '@rollup/plugin-terser';
import commonjs from '@rollup/plugin-commonjs';
import typescript from '@rollup/plugin-typescript';
import json from '@rollup/plugin-json';
import path from 'path';
import replace from '@rollup/plugin-replace';
import nodePolyfills from 'rollup-plugin-polyfill-node';
const outputFileName = 'clam';
const name = 'clam';
const defaultInput = './src/index.ts';
const extensions = ['.ts', '.tsx', '.js'];
const buildConfig = ({minifiedVersion = true, ...config }) => {
const { file } = config.output;
const ext = path.extname(file);
const basename = path.basename(file, ext);
const extArr = ext.split('.');
extArr.shift();
const build = ({ minified }) => ({
input: defaultInput,
...config,
output: {
...config.output,
file: `${path.dirname(file)}/${basename}.${(minified ? ['min', ...extArr] : extArr).join('.')}`
},
plugins: [
json(),
typescript(),
...(config.plugins || []),
minified && terser(),
minified && bundleSize(),
]
});
const configs = [
build({ minified: false }),
];
if (minifiedVersion) {
configs.push(build({ minified: true }));
}
return configs;
};
export default async () => {
return [
// browser ESM bundle for CDN
...buildConfig({
input: defaultInput,
output: {
file: `dist/esm/${outputFileName}.mjs`,
format: 'esm',
exports: 'named'
},
plugins: [
replace({
preventAssignment: true,
values: {
'process.env.NODE_ENV': 'production',
'process.env.NODE_DEBUG': false
}
}),
commonjs(),
nodePolyfills(),
nodeResolve({ preferBuiltins: false, browser: true }),
]
}),
// Browser UMD bundle for CDN
// ...buildConfig({
// input: defaultInput,
// output: {
// file: `dist/${outputFileName}.js`,
// name,
// format: 'umd',
// exports: 'named',
// }
// }),
// Node.js commonjs bundle
...buildConfig({
input: defaultInput,
output: {
file: `dist/node/${name}.cjs`,
format: 'cjs',
exports: 'named',
},
plugins: [
autoExternal(),
commonjs()
]
})
];
};