-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
82 lines (74 loc) · 1.93 KB
/
rollup.config.mjs
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
import babel from '@rollup/plugin-babel';
import nodeResolve from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import commonjs from '@rollup/plugin-commonjs';
import typescript from 'rollup-plugin-typescript2';
import bundleSizes from 'rollup-plugin-bundle-size';
import json from '@rollup/plugin-json';
import pkg from './package.json' assert { type: 'json' };
const IS_PROD = process.env.NODE_ENV === 'production';
console.log(process.env.NODE_ENV);
const INPUT_FILE = './src/index.ts';
const INPUT_FILE_BROWSER = './src/browser.ts';
const OUTPUT_FILE_BROWSER = './dist/browser.min.js';
const getPlugins = (tsDeclaration = false) => [
typescript(
tsDeclaration
? {
useTsconfigDeclarationDir: true,
tsconfigOverride: {
compilerOptions: {
declaration: true,
declarationDir: 'dist/types',
},
exclude: ['**/dist'],
},
}
: {},
),
babel({ babelHelpers: 'bundled' }),
json(),
nodeResolve({ mainFields: ['module', 'jsnext'] }),
commonjs({ include: 'node_modules/**' }),
bundleSizes(),
];
const cjs = {
plugins: IS_PROD ? [...getPlugins(true), terser()] : getPlugins(true),
input: INPUT_FILE,
output: {
sourcemap: "inline",
exports: 'named',
file: pkg.main,
format: 'cjs',
},
};
const es = {
plugins: getPlugins(),
input: INPUT_FILE,
output: {
sourcemap: "inline",
file: pkg.module,
format: 'es',
},
};
const umd = {
plugins: IS_PROD ? [...getPlugins(), terser()] : getPlugins(),
input: INPUT_FILE,
output: {
sourcemap: "inline",
exports: 'named',
name: pkg.umdName,
file: pkg.browser,
format: 'umd',
},
};
const browser = {
plugins: [...getPlugins(), terser()],
input: INPUT_FILE_BROWSER,
output: {
sourcemap: "inline",
file: OUTPUT_FILE_BROWSER,
format: 'iife',
},
};
export default IS_PROD ? [cjs, es, umd, browser] : umd;