npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

babel-plugin-console-transform

v0.0.4

Published

一个生产环境删除console,开发环境扩展console支持打印颜色和代码位置的babel插件

Downloads

9

Readme

:rainbow:一个生产环境删除console,开发环境扩展console支持打印颜色和代码位置的babel插件

🌰源码:

🌰生产环境:

🌰非生产环境:

:film_projector:效果:

特性 :grinning:

:x: 生产环境删除所有console,也可以通过glob字符串或者函数来自定义删除逻辑

:rainbow: 非生产环境可以扩展console方法,默认提供了几种console方法,green、blue、orange、red、bgGreen、bgOrange、bgBlue、bgRed

🏷️ 扩展的方法会自动添加代码文件和行列数,如 /src/scripts/inde.js (10:5)

安装 :kissing_smiling_eyes:

npm install --save-dev babel-plugin-console-transform

or

yarn add --dev babel-plugin-console-transform

使用 :thinking:

在.babelrc.js引入插件并配置

const consoleTransformPlugin = require('babel-plugin-console-transform');

module.exports = {
    plugins: [
        [
            consoleTransformPlugin,
            {
                env: 'production',
                removeMethods: ["*g*", (args) => args.includes('xxxx')],
                additionalStyleMethods: {
                    'success': 'padding:10px; color:#fff;background:green;',
                    'danger': 'padding:20px; background:red;font-size:30px; color:#fff;'
                }
            }
        ]
    ]
}

配置项 :sunglasses:

| 配置项名称 | 是否必须 | 含义 | 类型 | 举例 |
| --- | --- | --- | --- | --- |
| env | 是 | 运行环境 | string | production, development|
| removeMethods | 否 | production下删除的方法,默认删除全部 | Array<string | Function> | ['log', 'warn'], [(args) => args.includes('dont remove'), 'log'] | additionalStyleMethods | 否 | 额外添加的console方法 | {[key: string]: string}| {'success': 'background: green;'}|

其他说明::unamused:

:tomato: env 配置时可以使用 process.env.NODE_ENV 指定

:kiwi_fruit: removeMethods 在 env 为 production 时才会生效,支持 glob模式 的字符串,比如 \*\*g**, **bg{Red,Green} 等,也支持函数,参数为console方法的参数,用于一些需要根据参数确定是否删除console的场景。

:peach: additionalStyleMethods可以扩展一些方法,而且可以覆盖原生的log等方法

:grapes: 所有扩展的方法都会额外打印文件路径和代码所在行列数

贡献 :heart:

欢迎任何形式的贡献。你可以用 pull requestsissues 的方式提交任何想法。

License

MIT. Copyright (c) 2019 lingxiaoguang