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-comment-log

v1.0.2

Published

Babel plugin that automatically inserts logs based on comment

Readme

babel-plugin-comment-log

A Babel plugin that injects logging code based on comments in React components.

Example

In

// @log(member, horses, score)

Out

{ member : ["ahn", "lee", "choi"], horses : ["horse1", "horse2"], score : 13 }

Installation

npm install --save-dev babel-plugin-comment-log

Usage

For Next.js Projects

Next.js uses .babelrc for Babel configuration. To integrate babel-plugin-comment-log into your Next.js project, update your .babelrc file as follows:

{
  "presets": ["next/babel"],
  "plugins": ["babel-plugin-comment-log"],
  "ignore": ["node_modules"]
}

Note: The next/babel preset includes necessary configurations for Next.js, ensuring compatibility with both ES6+ syntax and React JSX. If your project already uses this preset, no additional configuration is needed.

For General React Projects

If you're not using Next.js, you can configure Babel using .babelrc. Here's how to set it up:

  1. Create or update .babelrc in the root of your project:
{
  "presets": ["@babel/preset-env", "@babel/preset-react"],
  "plugins": ["babel-plugin-comment-log"],
  "ignore": ["node_modules"]
}
  1. Ensure Babel is properly configured in your project. If you already have a babel.config.js or .babelrc file, make sure to include the babel-plugin-comment-log in the plugins array.

Note: The @babel/preset-env and @babel/preset-react presets are used to transpile modern JavaScript and React JSX syntax. If your project already uses these presets, you only need to add babel-plugin-comment-log to the plugins array.

How It Works

By adding a // @log comment at the top of your React functional components, this plugin automatically injects a useEffect hook that logs the specified variables whenever they change.

In your React component

import React, { useState } from 'react';

// @log(count, horses, ids)
function MyComponent(props) {
  const [count, setCount] = useState(0);
  const [horses, setHorses] = useState(['horse1', 'horse2']);
  const ids = useSelector((state) => state.ids);

  // Your component logic...

  return <div>...</div>;
}

export default MyComponent;

Resulting Code

After applying the plugin, the component will be transformed as follows:

import React, { useState, useEffect } from 'react';

function MyComponent(props) {
  const [count, setCount] = useState(0);
  const [horses, setHorses] = useState(['horse1', 'horse2']);
  const ids = useSelector((state) => state.ids);

  // Automatically injected useEffect by babel-plugin-comment-log
  useEffect(() => {
    console.log({ count, horses, ids });
  }, [count, horses, ids]);

  // Your component logic...

  return <div>...</div>;
}

export default MyComponent;

Production Mode

In production mode, the plugin does nothing, and no extra code is added to your bundle, ensuring optimal performance.

⚠️ Important Notes

  1. Not compatible with class components: This plugin is designed to work only with functional components and cannot be used in class components.

  2. Server components limitation (Next.js 13+): This plugin will cause errors if used within server components in Next.js 13 or higher. It is intended for use in client components only, so please ensure correct component types when using Next.js 13 or newer.

📄 LICENSE

MIT LICENSE