Skip to content

Commit

Permalink
Merge pull request #16 from mrbar42/support-webpack-5
Browse files Browse the repository at this point in the history
Support Webpack 5
  • Loading branch information
mrbar42 committed Oct 28, 2020
2 parents 4420251 + 0e2070a commit 6a2a98a
Show file tree
Hide file tree
Showing 13 changed files with 403 additions and 2,195 deletions.
1 change: 1 addition & 0 deletions .node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10
4 changes: 3 additions & 1 deletion es5/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Compiler } from "webpack";
import { Compiler } from 'webpack';
declare class IgnoreEmitPlugin {
private readonly options;
private readonly DEBUG;
Expand Down
26 changes: 22 additions & 4 deletions index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion index.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 27 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
'use strict';

import {Compiler} from "webpack";
import * as webpack from "webpack";
import Compilation = webpack.compilation.Compilation;
import {Compilation, Compiler} from 'webpack';

class IgnoreEmitPlugin {
private readonly options: { debug?: boolean };
Expand Down Expand Up @@ -51,17 +49,39 @@ class IgnoreEmitPlugin {
Object.keys(compilation.assets).forEach(assetName => {
if (this.checkIgnore(assetName, this.ignorePatterns)) {
this.DEBUG && console.log(`IgnoreEmitPlugin: Ignoring asset ${assetName}`);
delete compilation.assets[assetName];
if (typeof compilation.deleteAsset === 'function') {
// Webpack 5
compilation.deleteAsset(assetName);
} else {
// older versions
delete compilation.assets[assetName];
}
}
});
};

// webpack 4
if (compiler.hooks && compiler.hooks.emit) {
compiler.hooks.emit.tap('IgnoreEmitPlugin', ignoreAssets);
// webpack 4/5
if (compiler.hooks && compiler.hooks.compilation) {
// compiler.hooks.emit.tap('IgnoreEmitPlugin', ignoreAssets);
compiler.hooks.compilation.tap(
'IgnoreEmitPlugin',
(compilation: Compilation) => {
compilation.hooks.processAssets.tap(
{
name: 'IgnoreEmitPlugin',
stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONS
},
() => {
ignoreAssets(compilation);
}
);
}
);

}
// webpack 3
else {
// @ts-ignore - this signature does not exist on the latest webpack typing
compiler.plugin('emit', (compilation, callback) => {
ignoreAssets(compilation);
callback();
Expand Down
Loading

0 comments on commit 6a2a98a

Please sign in to comment.