@rushstack/webpack-plugin-utilities
0.4.87 • Public • Publishednpm install @rushstack/webpack-plugin-utilities --save
This is a collection of utilities for writing webpack plugins
import{VersionDetection}from"@rushstack/webpack-plugin-utilities"classMyExampleWebpackPlugin{constructor(){this.pluginName="MyExampleWebpackPlugin"}apply(compiler){if(VersionDetection.isWebpack3OrEarlier(compiler)){thrownewError(`This plugin does not support webpack 3 or below.`)}constisWebpack4=VersionDetection.isWebpack4(compiler);if(isWebpack4){compiler.hooks.compilation.tap(this.pluginName,(compilation)=>{// ....});}else{compiler.hooks.compilation.tap(this.pluginName,(compilation)=>{// ...});}}}
import{getTestingWebpackCompiler}from"@rushstack/webpack-plugin-utilities"describe("MyPlugin",()=>{it("should run",async()=>{conststats=awaitgetTestingWebpackCompiler("./src/index.ts");expect(stats).toBeDefined();});});
If you want to pass in additional configuration to the webpack compiler, you can pass it in as the second parameter togetTestingWebpackCompiler
.
import{getTestingWebpackCompiler}from"@rushstack/webpack-plugin-utilities"describe("MyPlugin",()=>{it("should run",async()=>{conststats=awaitgetTestingWebpackCompiler("./src/index.ts",{mode:"production",});expect(stats).toBeDefined();});});
If you want to be able to read, analyze, access the files written to the memory filesystem,you can pass in a memory filesystem instance to thememFs
parameter.
import{getTestingWebpackCompiler}from"@rushstack/webpack-plugin-utilities"import{createFsFromVolume,Volume,IFs}from"memfs"importpathfrom"path"describe("MyPlugin",()=>{it("should run",async()=>{constvirtualFileSystem:IFs=createFsFromVolume(newVolume());conststats=awaitgetTestingWebpackCompiler(`./src/index.ts`,{},virtualFileSystem);expect(stats).toBeDefined();expect(virtualFileSystem.existsSync(path.join(__dirname,"dist","index.js"))).toBe(true);});});
- CHANGELOG.md - Findout what's new in the latest version
@rushstack/webpack-plugin-utilities
is part of theRush Stack family of projects.
Readme
Keywords
nonePackage Sidebar
Install
npm i @rushstack/webpack-plugin-utilities
Repository
Weekly Downloads
9,511
Version
0.4.87
License
MIT
Unpacked Size
119 kB
Total Files
18