This repository has been archived by the owner on Jun 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rollup.config.js
75 lines (71 loc) · 1.73 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
// @ts-check
import { terser } from 'rollup-plugin-terser';
import nodeResolve from 'rollup-plugin-node-resolve';
import filesize from 'rollup-plugin-filesize';
import tslint from 'rollup-plugin-tslint';
import typescript from 'rollup-plugin-typescript2';
const NODE_ENV = process.env.NODE_ENV;
const isProd = 'production' === NODE_ENV;
const isTest = 'test' === NODE_ENV;
const input = ['src/index.ts'];
const pluginFn = (iife = false) => [
nodeResolve(),
isProd && tslint({
throwError: true,
configuration: `tslint${isProd ? '.prod' : ''}.json`,
}),
typescript({
tsconfig: './tsconfig.json',
exclude: isProd ? ['src/(demo|test)/**/*'] : [],
...(iife ? { tsconfigOverride: { compilerOptions: { target: 'es5' } } } : {}),
}),
isProd && terser(),
isProd && filesize({ showBrotliSize: true }),
];
const multiBuild = [
{
file: 'dist/index.mjs',
format: 'esm',
sourcemap: true,
exports: 'named',
},
{
file: 'dist/index.js',
format: 'cjs',
sourcemap: true,
exports: 'named',
},
{
file: 'dist/deep.clone.js',
format: 'esm',
sourcemap: true,
// exports: 'named',
},
{
file: 'dist/deep.clone.iife.js',
name: 'DeepClone',
format: 'iife',
sourcemap: true,
exports: 'named',
},
].map(n => ({ input, output: n, plugins: pluginFn('iife' === n.format) }));
const testBuild = [
{
input: 'src/index.ts',
output: {
file: 'dist/index.js',
format: 'cjs',
sourcemap: true,
exports: 'named',
},
plugins: [
nodeResolve(),
typescript({
tsconfig: './tsconfig.json',
include: ['src/*.ts'],
exclude: ['src/(demo|test)/**/*.ts'],
}),
],
},
];
export default isTest ? testBuild : multiBuild;