-
Notifications
You must be signed in to change notification settings - Fork 2
/
rollup.config.js
62 lines (60 loc) · 1.61 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
const defineConfig = require('rollup').defineConfig
// 使用 require 语法导入 Babel 插件
const babel = require('rollup-plugin-babel')
// 使用 require 语法导入 TypeScript 插件
const typescript = require('@rollup/plugin-typescript')
// 使用 require 语法导入 Node Resolve 插件
const resolve = require('@rollup/plugin-node-resolve')
// 使用 require 语法导入 CommonJS 插件
const commonjs = require('@rollup/plugin-commonjs')
const { terser } = require('rollup-plugin-terser')
// 使用 require 语法动态引入 package.json
const pkg = require('./package.json')
// 动态设置打包名称
const libName = pkg.name
const banner = `/*!
* ${libName}
* ${pkg.description}
* Author: ${pkg.author.name}
* Email: ${pkg.author.email}
* Repository: ${pkg.homepage}
* Version: ${pkg.version}
* License: ${pkg.license}
*/`
module.exports = defineConfig({
input: 'main/index.ts',
output: [
{
file: `dist/${libName}.cjs.js`,
format: 'cjs',
banner,
sourcemap: true
},
{
file: `dist/${libName}.es.js`,
format: 'es',
banner,
sourcemap: true
},
{
file: `dist/${libName}.umd.js`,
// UMD 格式,可以用于 Node 和浏览器等多个场景
format: 'umd',
name: libName,
exports: 'named',
banner,
sourcemap: true
}
],
plugins: [
babel(),
typescript({
sourceMap: true,
tsconfig: './tsconfig.json', // 指定 tsconfig.json 文件的位置
outDir: './dist/types' // 声明文件将输出到这个目录,与 declarationDir
}),
resolve(),
commonjs(),
terser()
]
})