@purekit/rollup-config 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/index.mjs +85 -69
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/index.mjs
CHANGED
|
@@ -1,69 +1,85 @@
|
|
|
1
|
-
import typescript from "@rollup/plugin-typescript";
|
|
2
|
-
import resolve from "@rollup/plugin-node-resolve";
|
|
3
|
-
import commonjs from "@rollup/plugin-commonjs";
|
|
4
|
-
import terser from
|
|
5
|
-
import dts from "rollup-plugin-dts";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
*
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
finalOutput =
|
|
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
|
-
|
|
1
|
+
import typescript from "@rollup/plugin-typescript";
|
|
2
|
+
import resolve from "@rollup/plugin-node-resolve";
|
|
3
|
+
import commonjs from "@rollup/plugin-commonjs";
|
|
4
|
+
import terser from "@rollup/plugin-terser";
|
|
5
|
+
import dts from "rollup-plugin-dts";
|
|
6
|
+
import alias from "@rollup/plugin-alias";
|
|
7
|
+
import path from "path";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 创建 Rollup 配置
|
|
11
|
+
* @param {Object} options 自定义选项
|
|
12
|
+
* @param {string} options.input 入口文件,默认为 "src/index.ts"
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export function createConfig(options = {}) {
|
|
16
|
+
const input = options.input || "src/index.ts";
|
|
17
|
+
const dist = "dist";
|
|
18
|
+
|
|
19
|
+
// 2. 获取当前执行构建的项目根目录
|
|
20
|
+
const projectRoot = process.cwd();
|
|
21
|
+
|
|
22
|
+
// 1. 定义默认输出 (CJS + ESM)
|
|
23
|
+
const defaultOutput = [
|
|
24
|
+
{
|
|
25
|
+
file: `${dist}/index.js`,
|
|
26
|
+
format: "cjs",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
file: `${dist}/index.mjs`,
|
|
30
|
+
format: "es",
|
|
31
|
+
},
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
// 2. 决定最终使用哪个 Output (优先用传入的,否则用默认的)
|
|
35
|
+
let finalOutput = options.output || defaultOutput;
|
|
36
|
+
|
|
37
|
+
// 3. 【关键】强制处理 sourcemap: false
|
|
38
|
+
if (!Array.isArray(finalOutput)) {
|
|
39
|
+
finalOutput = [finalOutput];
|
|
40
|
+
}
|
|
41
|
+
finalOutput = finalOutput.map((item) => ({
|
|
42
|
+
...item,
|
|
43
|
+
sourcemap: false,
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
const jsConfig = {
|
|
47
|
+
input,
|
|
48
|
+
output: finalOutput, // 使用处理后的 output
|
|
49
|
+
external: (id) => /node_modules/.test(id),
|
|
50
|
+
plugins: [
|
|
51
|
+
alias({
|
|
52
|
+
entries: [
|
|
53
|
+
{
|
|
54
|
+
find: "@",
|
|
55
|
+
replacement: path.resolve(projectRoot, "src"),
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
}),
|
|
59
|
+
resolve(),
|
|
60
|
+
commonjs(),
|
|
61
|
+
typescript({
|
|
62
|
+
tsconfig: "./tsconfig.json",
|
|
63
|
+
declaration: false,
|
|
64
|
+
}),
|
|
65
|
+
/build/.test(process.env.npm_lifecycle_event || "")
|
|
66
|
+
? terser({
|
|
67
|
+
format: { comments: false },
|
|
68
|
+
compress: {
|
|
69
|
+
drop_console: false,
|
|
70
|
+
drop_debugger: true,
|
|
71
|
+
pure_funcs: ["console.log", "console.info", "console.debug"],
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
: null,
|
|
75
|
+
],
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const dtsConfig = {
|
|
79
|
+
input,
|
|
80
|
+
output: [{ file: `${dist}/index.d.ts`, format: "es" }],
|
|
81
|
+
plugins: [dts()],
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return [jsConfig, dtsConfig];
|
|
85
|
+
}
|