-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
76 lines (72 loc) · 2.05 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
import { defineConfig } from 'rollup';
import terser from "@rollup/plugin-terser"
import { nodeResolve } from '@rollup/plugin-node-resolve'; //rollup默认只能是绝对路径,可处理相对路径,省略引入文件的后缀名称(可省略的名称需要配置)
import commonjs from '@rollup/plugin-commonjs'; //rollup默认只支持 ES6+的模块方式,使支持引用commonjs的包
import externals from "rollup-plugin-node-externals"; //自动将 dependencies 依赖声明为 externals
import json from '@rollup/plugin-json';
import { babel } from '@rollup/plugin-babel';
import dts from "rollup-plugin-dts";
export default defineConfig([
{
input: "src/index.ts",
output: [
{
file: './lib/cjs/index.js',
format: 'cjs',
},
// {
// dir: './lib/esm',
// format: 'es',
// // 只编译、不打包,按需引入
// preserveModules: true,
// },
{
file: './lib/esm/index.js',
format: 'es',
},
{
file: './lib/umd/index.min.js',
format: 'umd',
name: 'myLib',
exports: 'named',
globals: {
"@babel/runtime-corejs3/helpers/asyncToGenerator": "@babel/runtime-corejs3/helpers/asyncToGenerator",
"@babel/runtime-corejs3/helpers/regeneratorRuntime": "@babel/runtime-corejs3/helpers/regeneratorRuntime"
},
},
],
plugins: [
commonjs({
include: /node_modules/
}),
//要在nodeResolve之前
externals({}),
nodeResolve({
extensions: ['.js', '.ts', '.jsx', '.tsx', '.mjs', '.cjs', '.json', '.node']
}),
json(),
babel({
exclude: 'node_modules/**',
babelHelpers: 'runtime',
include: 'src/**',
extensions: [".ts", ".js"],
}),
terser({
compress: {
drop_console: true,
drop_debugger: true
}
}),
],
},
{
input: "src/index.ts",
output: [
{
file: "lib/typings/index.d.ts",
format: "es"
}
],
plugins: [dts()],
},
])