Last Call Webpack Plugin

raw JSON →
3.0.0 verified Sat Apr 25 auth: no javascript

A Webpack plugin that allows transforming/modifying assets just before Webpack emits them. Version 3.0.0 supports Webpack 4+, while v2.1.2 is for Webpack 3 and below. The plugin accepts an array of asset processors, each with a regex to match asset names and a processor function returning a Promise. It provides an assets object for adding, deleting, or retrieving assets during processing. Useful for prefixing comments, running final optimizations (e.g., cssnano), or generating additional assets like source maps. Compared to other asset modification plugins, it offers explicit per-processor phase control and direct asset manipulation.

error TypeError: LastCallWebpackPlugin is not a constructor
cause Using ESM import syntax with CommonJS-only module.
fix
Use require('last-call-webpack-plugin') instead of import.
error Error: webpack v4+ only supports last-call-webpack-plugin@3
cause Trying to use v2 with Webpack 4 or v3 with Webpack 3.
fix
Match plugin version to Webpack version: v2 for Webpack 3, v3 for Webpack 4+.
error TypeError: asset.source is not a function
cause processor receives webpack asset object, which may not have source() in older webpack versions or custom asset types.
fix
Check if asset.source exists, or use asset.buffer()/asset.content() depending on Webpack version.
breaking v3.0.0 requires Webpack 4 or higher; v2.x for Webpack 3 and below.
fix Downgrade to last-call-webpack-plugin@2.1.2 if using Webpack < 4.
deprecated Option phase: 'compilation.optimize-chunk-assets' may be deprecated in Webpack 5.
fix Consider using 'compilation.optimize-assets' or 'emit' phase instead.
gotcha processor function must return a Promise or a value (if synchronous). Asynchronous behavior relies on Promise.
fix Ensure processor returns a Promise or use async/await. For synchronous transforms, wrap in Promise.resolve().
gotcha The assets setAsset() method with null deletes the asset; does not provide feedback if asset missing.
fix Use getAsset() to check existence before deleting, or catch errors.
npm install last-call-webpack-plugin
yarn add last-call-webpack-plugin
pnpm add last-call-webpack-plugin

Shows typical usage with two processors: one to prepend a comment to JS files, another to minify CSS files using cssnano.

const LastCallWebpackPlugin = require('last-call-webpack-plugin');
const cssnano = require('cssnano');

module.exports = {
  entry: './src/index.js',
  output: {
    path: __dirname + '/dist',
    filename: 'bundle.js'
  },
  plugins: [
    new LastCallWebpackPlugin({
      assetProcessors: [
        {
          regExp: /\.js$/,
          processor: (assetName, asset) => Promise.resolve('// Author: John Doe\n' + asset.source())
        },
        {
          regExp: /\.css$/,
          processor: (assetName, asset, assets) => cssnano.process(asset.source()).then(r => r.css)
        }
      ],
      canPrint: true
    })
  ]
};