-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
62 lines (58 loc) · 1.57 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
import path from "path";
import rollupTypescript from "rollup-plugin-typescript2";
import babel from "rollup-plugin-babel";
import clear from "rollup-plugin-clear";
import { eslint } from "rollup-plugin-eslint";
import { DEFAULT_EXTENSIONS } from "@babel/core";
import pkg from "./package.json";
const paths = {
input: path.join(__dirname, "/src/index.ts"),
output: path.join(__dirname, "/lib"),
};
const getOutput = (name) => path.join(paths.output, name);
// rollup 配置项
const rollupConfig = {
input: paths.input,
output: [
{
file: getOutput("index.js"),
format: "cjs",
name: pkg.name,
},
{
file: getOutput("index.esm.js"),
format: "es",
name: pkg.name,
},
],
external: ["crypto-js"],
plugins: [
clear({ targets: ["lib"] }),
// 验证导入的文件
eslint({
throwOnError: true,
throwOnWarning: true,
include: ["src/**/*.ts"],
exclude: ["node_modules/**", "lib/**", "*.js", "test/**"],
}),
rollupTypescript(),
babel({
runtimeHelpers: true,
// 只转换源代码,不运行外部依赖
exclude: "node_modules/**",
// babel 默认不支持 ts 需要手动添加
extensions: [...DEFAULT_EXTENSIONS, ".ts"],
presets: [
[
"@babel/preset-env",
{
/* Babel 会在 Rollup 有机会做处理之前,将我们的模块转成 CommonJS,导致 Rollup 的一些处理失败 */
modules: false,
},
],
],
}),
clear({ targets: ["lib/test"] }),
],
};
export default rollupConfig;