Skip to content

Commit

Permalink
Merge pull request #6 from mrbar42/support-all-webpack-versions
Browse files Browse the repository at this point in the history
support both webpack 3 and 4
  • Loading branch information
mrbar42 committed Jul 2, 2018
2 parents 0926ad2 + 5059e4a commit 07b9846
Show file tree
Hide file tree
Showing 6 changed files with 1,808 additions and 2,634 deletions.
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
test/
.editorconfig
.travis.yml
.gitignore
18 changes: 15 additions & 3 deletions ignore-emit-webpack-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,30 @@ class IgnoreEmitPlugin {
}

return pattern.test(assetName);
})
});
}

apply(compiler) {
compiler.hooks.emit.tap('IgnoreEmitPlugin', compilation => {
const ignoreAssets = compilation => {
Object.keys(compilation.assets).forEach(assetName => {
if (this.checkIgnore(assetName, this.ignorePatterns)) {
this.DEBUG && console.log(`IgnoreEmitPlugin: Ignoring asset ${assetName}`);
delete compilation.assets[assetName];
}
});
});
};

// webpack 4
if (compiler.hooks && compiler.hooks.emit) {
compiler.hooks.emit.tap('IgnoreEmitPlugin', ignoreAssets);
}
// webpack 3
else {
compiler.plugin('emit', (compilation, callback) => {
ignoreAssets(compilation);
callback();
});
}
}
}

Expand Down
Loading

0 comments on commit 07b9846

Please sign in to comment.