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 🙏

© 2024 – Pkg Stats / Ryan Hefner

webpack-plugin-log-version

v0.6.2

Published

A webpack plugin that prepends a javacript bundle with project version information

Downloads

4

Readme

Webpack Plugin Log Version

A simple plugin for logging your project build version into the browser console. The purpose of the plugin is to help keep track of which version of a bundle is deployed where. This may be useful if you deploy different versions of a project in many places.

Note: This plugin is beta software. Please report bugs and contribute suggestions.

Requirements

  1. Webpack version 5 or greater
  2. Git (if using git features)

Usage

This guide assumes you already know how to setup a webpack configuration.

  1. First, install the plugin npm install -D webpack-plugin-log-version

  2. Import the plugin and add it to your config:

    const LogVersionPlugin = require('webpack-plugin-log-version')
    
    module.exports = {
      entry: './src/js/index.js',
      output: {
        filename: 'bundle.js',
        path: path.resolve(__dirname, 'dist') 
      },
      module: {
        rules: [
          { 
            test: /\.js$/,
            exclude: /(node_modules)/,
            use: {
              loader: 'babel-loader',
              options: {
                presets: ['@babel/preset-env']
              }
            },
          }
        ]
      },
      plugins: [
        new LogVersionPlugin()
      ]
    }
  3. Run a build of your project and load it in your browser. You should see an output log with the default settings:

    Example image of the plugin's default settings

Configuration

You may pass in a configuration object into the plugin to customize the output.

The configuration options and their defaults are as follows:

declare type PluginOptions = {
  color: string
  comment: string
  deployedBy: boolean | string,
  git: boolean
  global: boolean
  globalName?: string
  log: boolean
  name?: string
  template?: string
}
  • color: Choose a different color for the console.log output. Can be any browser console compatible keyword or HEX value.
  • comment: Add an optional comment to the end of your log
  • deployedBy: Include who built/deployed the bundle. This can be set to a string or true/false. If set to true along with git: true, the local git config user.name is used. Default : false
  • git: Enable git features and the project's branch and commit to the log Default: true
  • global: Add an object to the global (window) context that contains the log information. Default: false
  • globalName: change the key for the global object. Default: package.name
  • log: Enable logging the version information in the console: Default: true
  • name: Override the default project name for the version log. Default: package.name
  • template: Override the console.log template for the version information. Uses EJS. Default: See Source

Template Variables

The plugin uses the following variables if they exist in the template already:

  • branch: working directory branch
  • color: log color
  • comment: the optional comment
  • commit: the latest commit (HEAD)
  • date: today's date
  • name: project name
  • version: project version

You may change up the template or re-arrange the output as you see fit with the plugin's template option.

Examples

  1. Omit the console log, but add an object to the window global. Give it an easier name to type:
    new LogVersionPlugin({
        log: false,
        global: true,
        globalName: 'myAwesomeLog'
    })
    This will generate: window.myAwesomeLog = {name: package.name, version: package.version, ...etc} and prevent logging the version out loud in the console
  2. Override the default template with a simpler log:
    new LogVersionPlugin({
        git: false,
        name: 'Example Bundle',
        template: '<%= name %> - <%= version %> - <%= date %>'
    })
    Output: Example Bundle - 1.2.0 - Wed May 26 2021
  3. Display the version information in hot pink & add a comment to it
    new LogVersionPlugin({
        color: 'hotpink',
        comment: "This bundle is lit! 🔥"
    })
    This bundle is lit

Getting Help & Contributing

Please leave an issue and explain the problem. Be as detailed as possible. If you wish to contribute feel free to submit pull requests and issues with your features and requests.

If you wish to contribute pull requests, please use the contrib branch