@purekit/rollup-config 1.1.0 → 1.2.0

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/index.mjs +82 -69
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @purekit/rollup-config
2
2
 
3
+ ## 1.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - feat: 调整打包不生成注释
8
+
9
+ ## 1.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - feat:新增别名配置
14
+
3
15
  ## 1.1.0
4
16
 
5
17
  ### Minor Changes
package/index.mjs CHANGED
@@ -1,69 +1,82 @@
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
-
7
- /**
8
- * 创建 Rollup 配置
9
- * @param {Object} options 自定义选项
10
- * @param {string} options.input 入口文件,默认为 "src/index.ts"
11
- */
12
- export function createConfig(options = {}) {
13
- const input = options.input || "src/index.ts";
14
- const dist = "dist";
15
-
16
- // 1. 定义默认输出 (CJS + ESM)
17
- const defaultOutput = [
18
- {
19
- file: `${dist}/index.js`,
20
- format: "cjs",
21
- },
22
- {
23
- file: `${dist}/index.mjs`,
24
- format: "es",
25
- },
26
- ];
27
-
28
- // 2. 决定最终使用哪个 Output (优先用传入的,否则用默认的)
29
- let finalOutput = options.output || defaultOutput;
30
-
31
- // 3. 【关键】强制处理 sourcemap: false
32
- if (!Array.isArray(finalOutput)) {
33
- finalOutput = [finalOutput];
34
- }
35
- finalOutput = finalOutput.map((item) => ({
36
- ...item,
37
- sourcemap: false, // 👈 强制覆盖
38
- }));
39
-
40
- const jsConfig = {
41
- input,
42
- output: finalOutput, // 使用处理后的 output
43
- external: (id) => /node_modules/.test(id),
44
- plugins: [
45
- resolve(),
46
- commonjs(),
47
- typescript({
48
- tsconfig: "./tsconfig.json",
49
- declaration: false,
50
- }),
51
- terser({
52
- format: { comments: false },
53
- compress: {
54
- drop_console: false,
55
- drop_debugger: true,
56
- pure_funcs: ["console.log", "console.info", "console.debug"],
57
- },
58
- }),
59
- ],
60
- };
61
-
62
- const dtsConfig = {
63
- input,
64
- output: [{ file: `${dist}/index.d.ts`, format: "es" }],
65
- plugins: [dts()],
66
- };
67
-
68
- return [jsConfig, dtsConfig];
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
+ export function createConfig(options = {}) {
15
+ const input = options.input || 'src/index.ts';
16
+ const dist = 'dist';
17
+
18
+ const projectRoot = process.cwd();
19
+
20
+ const defaultOutput = [
21
+ {
22
+ file: `${dist}/index.js`,
23
+ format: 'cjs',
24
+ },
25
+ {
26
+ file: `${dist}/index.mjs`,
27
+ format: 'es',
28
+ },
29
+ ];
30
+
31
+ let finalOutput = options.output || defaultOutput;
32
+
33
+ if (!Array.isArray(finalOutput)) {
34
+ finalOutput = [finalOutput];
35
+ }
36
+ finalOutput = finalOutput.map((item) => ({
37
+ ...item,
38
+ sourcemap: false,
39
+ }));
40
+
41
+ const isMinify = /(build|publish)/.test(process.env.npm_lifecycle_event || '');
42
+
43
+ const jsConfig = {
44
+ input,
45
+ output: finalOutput,
46
+ external: (id) => /node_modules/.test(id),
47
+ plugins: [
48
+ alias({
49
+ entries: [
50
+ {
51
+ find: '@',
52
+ replacement: path.resolve(projectRoot, 'src'),
53
+ },
54
+ ],
55
+ }),
56
+ resolve(),
57
+ commonjs(),
58
+ typescript({
59
+ tsconfig: './tsconfig.json',
60
+ declaration: false,
61
+ }),
62
+ isMinify
63
+ ? terser({
64
+ format: { comments: false },
65
+ compress: {
66
+ drop_console: false,
67
+ drop_debugger: true,
68
+ pure_funcs: ['console.log', 'console.info', 'console.debug'],
69
+ },
70
+ })
71
+ : null,
72
+ ],
73
+ };
74
+
75
+ const dtsConfig = {
76
+ input,
77
+ output: [{ file: `${dist}/index.d.ts`, format: 'es' }],
78
+ plugins: [dts()],
79
+ };
80
+
81
+ return [jsConfig, dtsConfig];
82
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@purekit/rollup-config",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "index.mjs",