-
Notifications
You must be signed in to change notification settings - Fork 5
/
rollup.config.js
48 lines (41 loc) · 1.24 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
import path from "path";
import commonjs from "rollup-plugin-commonjs"; // commonjs模块转换插件
import { eslint } from "rollup-plugin-eslint"; // eslint插件
import resolve from "rollup-plugin-node-resolve"; // 依赖引用插件
import ts from "rollup-plugin-typescript2";
import { uglify } from "rollup-plugin-uglify";
import packageJSON from "./package.json";
const getPath = (_path) => path.resolve(__dirname, _path);
const extensions = [".js", ".ts", ".tsx"];
// ts
const tsPlugin = ts({
tsconfig: getPath("./tsconfig.json"), // 导入本地ts配置
extensions,
});
// eslint
const esPlugin = eslint({
throwOnError: true,
include: ["src/**/*.ts"],
exclude: ["node_modules/**", "lib/**"],
});
// 基础配置
const commonConf = {
input: getPath("./src/index.tsx"),
external: ["react"],
plugins: [uglify(), resolve(extensions), commonjs(), esPlugin, tsPlugin],
};
// 需要导出的模块类型
const outputMap = [
{
file: packageJSON.main, // 通用模块
format: "umd",
},
{
file: packageJSON.module, // es6模块
format: "es",
},
];
const buildConf = (options) => Object.assign({}, commonConf, options);
export default outputMap.map((output) =>
buildConf({ output: { name: packageJSON.name, ...output } })
);