Babel plugin that automatically inserts a logger declaration (via js-logger) at the top of every transpiled JavaScript file, enabling consistent logging across backend and frontend projects. Current stable version: 1.0.17. Maintained as of early 2021, with infrequent updates. Key differentiators: automatic logger instantiation per file, configurable logger name formatting (project/level/separator/extensions), and support for both Babel standalone and Webpack. Alternative to manual logger setup in each file. Note: requires js-logger as a peer dependency and Babel as a build tool.
npm install babel-plugin-js-loggerVerified import paths — ran on the pinned version, not inferred.
Installs and configures the plugin, initializes js-logger, and demonstrates automatic logger insertion per file.
Use a separate init file imported first, e.g., import './logger-init.js'; (see README).
Consider using manual logger setup if tree-shaking is critical.
Test with your project structure and adjust level or extensions accordingly.
Use @babel/preset-typescript and ensure the plugin runs after it.
Install js-logger as a dependency: npm install js-logger --save
Install the plugin: npm install babel-plugin-js-logger --save-dev, then add 'js-logger' to .babelrc plugins array.
Call require('js-logger').useDefaults() before using the generated logger variables.