适配 WinJS 的控制台输出移除插件。
在生产环境构建时自动移除代码中的 console
语句,减少打包体积并提升性能。该插件基于 unplugin-remove
实现,同时支持 Vite 和 Webpack 构建工具。
- 🚀 构建时移除: 仅在构建(build)过程中运行,不影响开发环境
- 🔧 双构建支持: 同时支持 Vite 和 Webpack 构建工具
- ⚙️ 灵活配置: 支持自定义配置选项
- 📦 零配置: 开箱即用,无需额外配置
npm install @winner-fed/plugin-remove-console --save-dev
# 或者
yarn add @winner-fed/plugin-remove-console
# 或者
pnpm add @winner-fed/plugin-remove-console
或者使用 yarn:
yarn add @winner-fed/plugin-remove-console --dev
在 WinJS 项目中,插件会自动检测并移除构建时的 console 语句:
// 开发环境 - 保留 console
console.log('这是开发环境的日志');
console.warn('这是警告信息');
console.error('这是错误信息');
// 生产环境构建后 - 自动移除上述 console 语句
在 win.config.ts
中进行配置:
import { defineConfig } from '@winner-fed/winjs';
export default defineConfig({
plugins: [
// 其他插件...
],
removeConsole: {
// 配置选项
}
});
export default defineConfig({
removeConsole: {
// 自定义要移除的方法
include: ['console.log', 'console.warn'],
// 排除特定的方法
exclude: ['console.error'],
// 其他 unplugin-remove 配置选项
}
});
参数 | 类型 | 默认值 | 描述 |
---|---|---|---|
include |
string[] |
undefined |
指定要移除的方法 |
exclude |
string[] |
undefined |
指定要排除的方法 |
更多配置选项请参考 unplugin-remove 文档。
- 基于
unplugin-remove
实现跨构建工具支持 - 通过 AST 分析和转换自动移除指定的函数调用
- 支持 Vite 和 Webpack 两种构建工具
unplugin-remove
: 核心移除功能实现
- 仅构建时生效: 插件只在
npm run build
时运行,开发环境不会移除 console 语句 - 生产环境推荐: 建议在生产环境中使用,以减少打包体积
- 调试影响: 移除 console 语句后,可能会影响生产环境的调试,请谨慎使用
MIT.