Skip to content

Commit

Permalink
Merge pull request #19 from mrbar42/webpack4-plugin-fix
Browse files Browse the repository at this point in the history
explicitly check webpack version major, add plugin tests
  • Loading branch information
mrbar42 committed Nov 23, 2020
2 parents 5caee04 + 807714c commit 8b8cbde
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 8 deletions.
5 changes: 4 additions & 1 deletion es5/index.js

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

5 changes: 4 additions & 1 deletion 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.

5 changes: 4 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class IgnoreEmitPlugin {
};

// webpack 5
if (compiler.hooks && compiler.hooks.compilation && version) {
if (compiler.hooks && compiler.hooks.compilation && version && Number(version[0]) > 4) {
this.DEBUG && console.log('Using Webpack5 format');
compiler.hooks.compilation.tap(
'IgnoreEmitPlugin',
(compilation: Compilation) => {
Expand All @@ -85,10 +86,12 @@ class IgnoreEmitPlugin {
}
// webpack 4
else if (compiler.hooks && compiler.hooks.emit) {
this.DEBUG && console.log('Using Webpack4 format');
compiler.hooks.emit.tap('IgnoreEmitPlugin', ignoreAssets);
}
// webpack 3
else {
this.DEBUG && console.log('Using Webpack3 or older format');
// @ts-ignore - this signature does not exist on the latest webpack typing
compiler.plugin('emit', (compilation, callback) => {
ignoreAssets(compilation);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ignore-emit-webpack-plugin",
"version": "2.0.5",
"version": "2.0.6",
"description": "Prevents ignored files from being emitted during a Webpack build",
"scripts": {
"test:webpack": "bash test/run-tests.sh",
Expand Down
7 changes: 4 additions & 3 deletions test/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ function run() {
exit 1
fi

npm ci
# npm ci

test_webpack "Webpack3" "[email protected] webpack-cli@2" "webpack3.config.js" || failed=1
test_webpack "Webpack4" "[email protected] webpack-cli@3" "webpack4.config.js" || failed=1
test_webpack "Webpack5" "[email protected] webpack-cli@4" "webpack5.config.js" || failed=1
test_webpack "WebpackLatest" "webpack@latest webpack-cli@latest" "webpack.config.js" || failed=1
test_webpack "Webpack4+Plugins" "[email protected] webpack-cli@3 [email protected]" "webpack-terser.config.js" || failed=1

npm ci
# npm ci

if [[ "$failed" ]]; then
echo "Some tests failed!"
Expand All @@ -42,7 +43,7 @@ function test_webpack() {
fi

# build
output="$(node_modules/.bin/webpack --config "test/$config" 2>&1)"
output="$(node_modules/.bin/webpack --config "test/$config" --bail --color 2>&1)"
echo "$output"

does_contain_deprecation=$(echo "$output" | grep -i "Warning" || echo '')
Expand Down
26 changes: 26 additions & 0 deletions test/webpack-terser.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

const webpack = require('webpack');
const IgnoreEmitPlugin = require('../');
const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
bail: true,
mode: 'production',
entry: {
app: './test/app.js'
},
output: {
publicPath: '',
chunkFilename: `[name].js`,
path: __dirname + '/tmp'
},
plugins: [
new IgnoreEmitPlugin(/chunk\.js$/, {debug: true}),
new webpack.SourceMapDevToolPlugin()
],
optimization: {
minimize: true,
minimizer: [new TerserPlugin()]
}
};

0 comments on commit 8b8cbde

Please sign in to comment.