-
Notifications
You must be signed in to change notification settings - Fork 3
/
rollup.config.js
52 lines (50 loc) · 1.34 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
import autoExternal from 'rollup-plugin-auto-external';
import esbuild from 'rollup-plugin-esbuild';
import json from '@rollup/plugin-json';
import nodeResolve from '@rollup/plugin-node-resolve';
import builtinModules from 'builtin-modules';
import pkgJson from './package.json';
export default function odpRollupConfig(options) {
const resolveOptions = {
mainFields: ['jsnext:main', 'es2020', 'es2018', 'es2017', 'es2015', 'module', 'main'],
preferBuiltins: true,
extensions: ['.ts', '.js', '.mjs', '.node'],
modulesOnly: false,
browser: false
};
const plugins = [
json(),
autoExternal({
builtins: true,
peerDependencies: true,
dependencies: true
}),
nodeResolve(resolveOptions),
esbuild({
minify: true,
target: 'es2015'
})
];
const external = [...builtinModules];
const outputMain = {
input: 'src/index.ts',
treeshake: true,
output: [{ sourcemap: false, file: pkgJson.main, format: 'cjs' }],
plugins,
external,
...options
};
const outputModule = {
...outputMain,
output: [{ sourcemap: false, file: pkgJson.module, format: 'esm' }]
};
return [
outputMain,
outputModule,
{
...outputMain,
input: 'cli/cli.ts',
output: [{ sourcemap: false, file: 'bin/cli.js', format: 'cjs', banner: '#!/usr/bin/env node' }]
}
];
}