-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.mjs
44 lines (38 loc) · 1.26 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
import { babel } from '@rollup/plugin-babel';
import { nodeResolve } from '@rollup/plugin-node-resolve';
import terser from '@rollup/plugin-terser';
import typescript from '@rollup/plugin-typescript';
import peerDepsExternal from 'rollup-plugin-peer-deps-external';
const INPUT_DIR = './src/';
const OUTPUT_DIR = './dist/';
const IS_PRODUCTION = process.env.NODE_ENV === 'production';
const getPlugins = (declarationDir, minification = false) =>
[
typescript({
compilerOptions: {
rootDir: INPUT_DIR,
declaration: true,
declarationDir: `${declarationDir}`,
},
}),
babel({ babelHelpers: 'bundled' }),
nodeResolve(),
peerDepsExternal(),
minification && terser(),
].filter(Boolean);
const getOutput = () => ({
exports: 'named',
sourcemap: true,
preserveModules: true,
entryFileNames: (chunkInfo) => `${chunkInfo.name.replace('src/', '')}.js`,
});
const getModule = (format) => ({
input: `${INPUT_DIR}index.ts`,
plugins: getPlugins(`${OUTPUT_DIR}${format}/`, IS_PRODUCTION),
output: {
...getOutput(),
format: format,
dir: `${OUTPUT_DIR}${format}`,
},
});
export default [getModule('es'), getModule('cjs')];