-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrollup.config.js
More file actions
86 lines (80 loc) · 2.02 KB
/
Copy pathrollup.config.js
File metadata and controls
86 lines (80 loc) · 2.02 KB
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
83
84
85
86
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import json from '@rollup/plugin-json';
import alias from '@rollup/plugin-alias';
import typescript from 'rollup-plugin-typescript2';
import babel from '@rollup/plugin-babel';
import { terser } from 'rollup-plugin-terser';
import { join } from 'path';
/**
* There is a TypeError occur when import directly.
*
* Fix it according to this issue: https://github.com/egoist/rollup-plugin-esbuild/issues/361
*
* ```javascript
* import dts from 'rollup-plugin-dts'; // TypeError: dts is not a function
* import esbuild from 'rollup-plugin-esbuild'; // TypeError: esbuild is not a function
* ```
*/
import _dts from 'rollup-plugin-dts';
import _esbuild from 'rollup-plugin-esbuild';
const dts = _dts.default ?? _dts;
const esbuild = _esbuild.default ?? _esbuild;
const resolveDir = dir => join(__dirname, dir);
/**
* Entry file of the whole project
*/
const entries = ['lib/index.ts'];
/**
* List of basic plugin
*/
const plugins = [
babel({
babelrc: false,
babelHelpers: 'bundled',
presets: [['env', { modules: false }]],
}),
resolve({
preferBuiltins: true,
}),
alias({
entries: [{ find: 'lib', replacement: resolveDir('lib') }],
}),
json(),
typescript(),
commonjs(),
esbuild(),
terser(),
];
export default [
/**
* Configuration of the construction of the project subject.
*/
...entries.map(input => ({
input,
output: [
{
file: input.replace('lib/', 'dist/').replace('.ts', '.mjs'),
format: 'esm',
},
{
file: input.replace('lib/', 'dist/').replace('.ts', '.cjs'),
format: 'cjs',
},
],
external: [],
plugins,
})),
/**
* Configuration of the construction of the declaration file.
*/
...entries.map(input => ({
input,
output: {
file: input.replace('lib/', 'dist/').replace('.ts', '.d.ts'),
format: 'esm',
},
external: [],
plugins: [dts({ respectExternal: true })],
})),
];