Skip to content

Latest commit

 

History

History
 
 

webpack-plugin-utilities

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

webpack-plugin-utilities

Installation

npm install @rushstack/webpack-plugin-utilities --save

Overview

This is a collection of utilities for writing webpack plugins

Usage

import { VersionDetection } from "@rushstack/webpack-plugin-utilities"

class MyExampleWebpackPlugin {
  constructor() {
    this.pluginName = "MyExampleWebpackPlugin"
  }

  apply(compiler) {
    if (VersionDetection.isWebpack3OrEarlier(compiler)) {
      throw new Error(`This plugin does not support webpack 3 or below.`)
    }

    const isWebpack4 = VersionDetection.isWebpack4(compiler);

    if (isWebpack4) {
      compiler.hooks.compilation.tap(this.pluginName, (compilation) => {
        // ....
      });
    } else {
      compiler.hooks.compilation.tap(this.pluginName, (compilation) => {
        // ...
      });
    }
  }
}

Links

@rushstack/webpack-plugin-utilities is part of the Rush Stack family of projects.