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

last-call-webpack-plugin

v3.0.0

Published

A Webpack plugin that allows to transform \ modify assets just before Webpack emits them.

Downloads

8,270,149

Readme

Last Call Webpack Plugin

A Webpack plugin that allows you to transform \ modify assets just before Webpack emits them.

What does the plugin do?

It allows you to transform \ modify Webpack assets just before Webpack emits them (writes them to files or memory in case you are using something like Webpack dev server).

It can be used for example to:

  • Prefix a /* Author: John Doe */ comment on all the .js files Webpack generates.
  • Run some final optimization on all .css files Webpack generates.

Installation:

Using npm:

$ npm install --save-dev last-call-webpack-plugin

:warning: For webpack v3 or below please use [email protected]. The [email protected] version and above supports webpack v4.

Configuration:

The plugin can receive the following options:

  • assetProcessors: An Array of objects that describe asset processors:
    • regExp: A regular expression to match the asset name that the processor handles.
    • processor: A function with the signature of function(assetName, webpackAssetObject, assets) that returns a Promise. If the Promise returns a result this result will replace the assets content.
    • phase: The webpack compilation phase that at which the processor should be called. Default value is compilation.optimize-assets. Can be one of the following values:
      • compilation.optimize-chunk-assets
      • compilation.optimize-assets
      • emit
  • canPrint: A boolean indicating if the plugin can print messages to the console, defaults to true.

Note: An environment supporting Promises or a Promise polyfill is needed for this plugin to be used.

Example:

var cssnano = require('cssnano');
var LastCallWebpackPlugin = require('last-call-webpack-plugin');
module.exports = {
  module: {
    loaders: [
      { test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader") }
    ]
  },
  plugins: [
    new ExtractTextPlugin("styles.css"),
    new LastCallWebpackPlugin({
      assetProcessors: [
        {
          regExp:  /\.js$/,
          processor: (assetName, asset) => Promise.resolve('// Author: John Doe \n' + asset.source())
        }, {
          regExp:  /\.css$/,
          processor: (assetName, asset) => cssnano.process(asset.source())
            .then(r => r.css)
        }
      ],
      canPrint: true
    })
	]
}

Assets manipulation

The processor method is supplied an assets object that allows asset manipulation via the setAsset(assetName, assetValue) method. If assetValue is null the asset will be deleted. This object can be used to generate aditional assets (like source maps) or rename the an asset (create a new asset and delete the current one).

Example:

var cssnano = require('cssnano');
var LastCallWebpackPlugin = require('last-call-webpack-plugin');
module.exports = {
  module: {
    loaders: [
      { test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader") }
    ]
  },
  plugins: [
    new ExtractTextPlugin("styles.css"),
    new LastCallWebpackPlugin({
      assetProcessors: [{
        regExp:  /\.css$/,
        processor: (assetName, asset, assets) => {
          assets.setAsset(assetName + '.map', null); // Delete the <assetName>.map asset.
          assets.setAsset(assetName + '.log', 'All OK'); // Add the <assetName>.log asset with the content 'All OK'.
          return cssnano
            .process(asset.source())
            .then(r => r.css)
        }
      }],
      canPrint: true
    })
	]
}

The assets object also has a getAsset(assetName) method to get the content of an asset (returns undefined in case the asset does not exist).

License

MIT (http://www.opensource.org/licenses/mit-license.php)