• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

kgrz/babel-plugin-console-groupify: A small babel plugin that wraps console.logs ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

kgrz/babel-plugin-console-groupify

开源软件地址:

https://github.com/kgrz/babel-plugin-console-groupify

开源编程语言:

JavaScript 100.0%

开源软件介绍:

Console Groupify plugin for Babel

Scratching another itch with this. Sometimes when I'm developing in React, I wish there was a way to group the console.log statements when used inside the life-cycle functions, and add some kind of visual separation between console.logs in different functions.

This plugin checks for console.logs inside functions, and wraps them inside a console.group/console.groupEnd set, with the function name passed in as a variable for console.group. For example:

function aFunctionDeclaration () {
  console.log('hi');
}

const aFunctionExpression = function () {
  console.log('hi')
}

const anArrowFunction = () => {
  console.log('hi')
}

ends up looking like:

▼ aFunctionDeclaration
  | hi

▼ aFunctionExpression
  | hi

▼ anArrowFunction
  | hi

Combining this with the https://github.com/kgrz/babel-plugin-transform-console-log-variable-names, the printf-debugging becomes way better. For example, in a React component:

class MyComponent extends React.Component {
  componentWillReceiveProps ( nextProps ) {
    console.log(this.props);
    console.log(nextProps);
  }
}

prints out:

▼ componentWillReceiveProps
  | this.props: { prop1: "one" }
  | nextProps: { prop1: "two. what the!" }

Actual screenshot from actual usage:

both-plugins-together

Note that both these plugins are at a pretty alpha quality.

Usage

Install the module with:

npm install --save babel-plugin-console-groupify

Include it in your babel configuration either via .babelrc or webpack. Here's a .babelrc example:

{
	"presets": [...],
	"plugins": [
		"console-groupify"
	]
}

Known Issues

  • A spread operator inside a switch statement seems to be causing issues when used with the babel-transform-object-rest-spread plugin. For instance:

    function myReducer (state = {}, action = {}) {
      console.log('hi');
      switch (action.type) {
        case 'some_action':
          return { ...state, key: value }
      }
    }



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
noiron/react-webpack-babel-boilerplate发布时间:2022-04-13
下一篇:
dagostinelli/babel-preset-react-hmre发布时间:2022-04-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap