-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
63 lines (59 loc) · 1.68 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
// @ts-check
import path from 'path';
import builtins from 'builtin-modules';
import alias from '@rollup/plugin-alias';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import resolve from '@rollup/plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';
import { terser } from 'rollup-plugin-terser';
// tslint:disable-next-line jsdoc
/** @type {(dir: string) => string} */
const resolveLocal = (dir) => path.join(__dirname, dir);
const pkg = require(resolveLocal('./package.json'));
// only packages contains native code should be set as external, the other should be bundled
const runtimeDeps = Object.keys(pkg.dependencies || {});
/** @type {import('rollup').RollupOptions} */
const config = {
input: resolveLocal('src/main.ts'),
output: [
{
file: resolveLocal('dist/main.js'),
format: 'cjs',
banner: '#!/usr/bin/env node',
sourcemap: process.env.NODE_ENV === 'development',
},
{
file: resolveLocal('dist/main.min.js'),
format: 'cjs',
banner: '#!/usr/bin/env node',
sourcemap: process.env.NODE_ENV === 'development',
plugins: [terser()],
},
],
plugins: [
alias({
entries: [
{
find: /^@\//,
replacement: resolveLocal('src/'),
},
],
}),
resolve(),
json(),
commonjs(),
typescript({
clean: true,
tsconfig: resolveLocal('src/tsconfig.app.json'),
tsconfigOverride: {
compilerOptions: {
module: 'ESNext',
},
},
}),
],
// Note: import nested module paths like 'xxx/es/comp' would have issue
external: builtins.concat(runtimeDeps),
};
export default config;