-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathrollup-config.js
More file actions
53 lines (47 loc) · 1.36 KB
/
rollup-config.js
File metadata and controls
53 lines (47 loc) · 1.36 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
import typescript from 'rollup-plugin-typescript2';
import json from '@rollup/plugin-json';
import commonjs from '@rollup/plugin-commonjs';
const defaultExternal = (id) =>
!id.startsWith('\0') &&
!id.startsWith('~') &&
!id.startsWith('.') &&
!id.startsWith(process.platform === 'win32' ? process.cwd() : '/');
const createOutput = (dir = 'dist', defaultOpts) => {
const { external, output, plugins = [], filename } = defaultOpts;
const defaultPlugins = [
commonjs({
ignoreDynamicRequires: true,
include: /\/node_modules\//,
}),
json(),
typescript({
rollupCommonJSResolveHack: true,
}),
];
const outputs = [
{
dir,
format: 'cjs',
chunkFileNames: filename ? `${filename}.js` : `[name].js`,
entryFileNames: filename ? `${filename}.js` : `[name].js`,
...output,
},
{
dir,
format: 'esm',
chunkFileNames: filename ? `${filename}.esm.js` : `[name].esm.js`,
entryFileNames: filename ? `${filename}.esm.js` : `[name].esm.js`,
...output,
},
];
return {
...defaultOpts,
external: external || defaultExternal,
plugins: defaultPlugins.filter(Boolean).concat(plugins),
output: outputs,
};
};
export function config(opts) {
const inputs = Array.isArray(opts) ? opts : [opts];
return inputs.map(({ dest: dir, ...opts }) => createOutput(dir, opts));
}