-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathrollup.config.js
85 lines (81 loc) · 2 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// 使用插件
import { nodeResolve } from "@rollup/plugin-node-resolve";
import commonjs from "@rollup/plugin-commonjs";
import terser from "@rollup/plugin-terser";
// 引入package.json
import pkg from "./package.json";
// 引入打包工具类
import { pathResolve } from "./build/utils/util.js";
// 引入打包路径
import { inputSrc, outputCjs, outputEsm, outputLib, outputRoot } from "./build/utils/paths.js";
// 声明注释
const banner = `/*
* ${pkg.name} v${pkg.version}
* Copyright 2021-${new Date().getFullYear()}, ${pkg.author}
* Released under the ${pkg.license} License.
*/`;
/**
* rollup 配置
*/
export default {
// 入口
input: pathResolve(inputSrc, "./index.js"),
// 输出
output: [
// 按需打包
{
format: "es",
entryFileNames: "[name].mjs",
preserveModules: true,
preserveModulesRoot: pathResolve(outputRoot, "src"),
dir: pathResolve(outputEsm),
exports: undefined,
},
{
format: "cjs",
entryFileNames: "[name].cjs",
preserveModules: true,
preserveModulesRoot: pathResolve(outputRoot, "src"),
dir: pathResolve(outputCjs),
exports: "named",
},
// 打全量包
{
format: "es",
entryFileNames: `index.full.esm.js`,
dir: pathResolve(outputLib),
exports: undefined,
banner,
},
{
format: "umd",
entryFileNames: `index.full.umd.js`,
dir: pathResolve(outputLib),
name: pkg.moduleName,
exports: "named",
banner,
},
// 打全量包-压缩包
{
format: "es",
entryFileNames: `index.full.esm.min.js`,
dir: pathResolve(outputLib),
exports: undefined,
banner,
plugins: [terser()],
},
{
format: "umd",
entryFileNames: `index.full.umd.min.js`,
dir: pathResolve(outputLib),
name: pkg.moduleName,
exports: "named",
banner,
plugins: [terser()],
},
],
// 排除模块
external: [],
// 使用插件
plugins: [nodeResolve(), commonjs()],
};