Skip to content

Commit

Permalink
Remove deprecation caused by the DeletedUnusuedEntriesJSPlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyrkan committed Dec 3, 2020
1 parent b0f7190 commit d576b21
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions lib/webpack/delete-unused-entries-js-plugin.js
Expand Up @@ -9,12 +9,13 @@

'use strict';

const webpack = require('webpack');

function DeleteUnusedEntriesJSPlugin(entriesToDelete = []) {
this.entriesToDelete = entriesToDelete;
}
DeleteUnusedEntriesJSPlugin.prototype.apply = function(compiler) {
const emit = (compilation, callback) => {

const deleteEntries = (compilation) => {
// loop over output chunks
compilation.chunks.forEach((chunk) => {
// see of this chunk is one that needs its .js deleted
Expand All @@ -26,7 +27,7 @@ DeleteUnusedEntriesJSPlugin.prototype.apply = function(compiler) {
if (/\.js?(\?[^.]*)?$/.test(filename)) {
removedFiles.push(filename);
// remove the output file
delete compilation.assets[filename];
compilation.deleteAsset(filename);
// remove the file, so that it does not dump in the manifest
chunk.files.delete(filename);
}
Expand All @@ -37,7 +38,7 @@ DeleteUnusedEntriesJSPlugin.prototype.apply = function(compiler) {
if (removedFiles.map(name => `${name}.map`).includes(`${filename}`)) {
removedFiles.push(filename);
// remove the output file
delete compilation.assets[filename];
compilation.deleteAsset(filename);
// remove the file, so that it does not dump in the manifest
chunk.auxiliaryFiles.delete(filename);
}
Expand All @@ -51,14 +52,14 @@ DeleteUnusedEntriesJSPlugin.prototype.apply = function(compiler) {
}
}
});

callback();
};

compiler.hooks.emit.tapAsync(
{ name: 'DeleteUnusedEntriesJsPlugin' },
emit
);
compiler.hooks.compilation.tap('DeleteUnusedEntriesJSPlugin', function (compilation) {
compilation.hooks.additionalAssets.tap(
'DeleteUnusedEntriesJsPlugin',
function() { deleteEntries(compilation) }
);
});
};

module.exports = DeleteUnusedEntriesJSPlugin;

0 comments on commit d576b21

Please sign in to comment.