diff --git a/package.json b/package.json index 9475afd..dabc0dc 100644 --- a/package.json +++ b/package.json @@ -23,6 +23,9 @@ "build": "rollup -c", "build:watch": "rollup -c -w", "prepublishOnly": "npm run build", + "patch": "npm version patch", + "minor": "npm version minor", + "publish": "npm publish", "postinstall": "echo 'Thanks for using our component library!'" }, "dependencies": { @@ -48,6 +51,7 @@ "@rollup/plugin-commonjs": "^29.0.0", "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^16.0.3", + "@rollup/plugin-terser": "^0.4.4", "glob": "^13.0.0", "rollup": "^4.54.0" } diff --git a/rollup.config.js b/rollup.config.js index 72bec25..1163c4e 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -2,6 +2,7 @@ import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; import json from '@rollup/plugin-json'; import babel from '@rollup/plugin-babel'; +import terser from '@rollup/plugin-terser'; import { readFileSync, existsSync } from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; @@ -195,6 +196,7 @@ const copyTypesPlugin = () => ({ * 3. commonjs - 转换 CommonJS 模块 * 4. json - 解析 JSON 导入(但被标记为 external,不会实际转换) * 5. copyTypesPlugin - 复制类型和样式文件 + * 6. terser - 代码压缩 */ const plugins = [ // 模块解析插件 - 解析 node_modules 中的模块 @@ -215,7 +217,24 @@ const plugins = [ json(), // 自定义插件 - 复制类型和样式文件 - copyTypesPlugin() + copyTypesPlugin(), + + // 代码压缩插件 + terser({ + compress: { + drop_console: false, // 保留 console + drop_debugger: true, // 移除 debugger + pure_funcs: [], // 不移除任何函数调用 + passes: 2 // 压缩次数 + }, + format: { + comments: false, // 移除注释 + beautify: false // 不美化代码,保持压缩格式 + }, + ecma: 2015, // 目标 ECMAScript 版本 + module: true, // 保留 ES 模块格式 + toplevel: false // 不压缩顶层作用域 + }) ]; /**