Skip to content

Commit 19efc54

Browse files
committed
DependencyExtractionWebpackPlugin: addressed code review feedback.
1 parent 88d02bc commit 19efc54

1 file changed

Lines changed: 11 additions & 9 deletions

File tree

  • packages/dependency-extraction-webpack-plugin/lib

packages/dependency-extraction-webpack-plugin/lib/index.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
* External dependencies
33
*/
44
const path = require( 'path' );
5-
const webpack = require( 'webpack' );
65
const json2php = require( 'json2php' );
7-
const { createHash } = webpack.util;
86

97
/**
108
* Internal dependencies
@@ -15,9 +13,6 @@ const {
1513
defaultRequestToHandle,
1614
} = require( './util' );
1715

18-
const { RawSource } = webpack.sources;
19-
const { AsyncDependenciesBlock } = webpack;
20-
2116
const defaultExternalizedReportFileName = 'externalized-dependencies.json';
2217

2318
class DependencyExtractionWebpackPlugin {
@@ -147,12 +142,13 @@ class DependencyExtractionWebpackPlugin {
147142
/** @type {webpack.WebpackPluginInstance['apply']} */
148143
apply( compiler ) {
149144
this.useModules = Boolean( compiler.options.output?.module );
145+
const { webpack } = compiler;
150146

151147
/**
152148
* Offload externalization work to the ExternalsPlugin.
153149
* @type {webpack.ExternalsPlugin}
154150
*/
155-
this.externalsPlugin = new compiler.webpack.ExternalsPlugin(
151+
this.externalsPlugin = new webpack.ExternalsPlugin(
156152
this.useModules ? 'import' : 'window',
157153
this.externalizeWpDeps.bind( this )
158154
);
@@ -165,16 +161,15 @@ class DependencyExtractionWebpackPlugin {
165161
compilation.hooks.processAssets.tap(
166162
{
167163
name: this.constructor.name,
168-
stage: compiler.webpack.Compilation
164+
stage: webpack.Compilation
169165
.PROCESS_ASSETS_STAGE_OPTIMIZE_COMPATIBILITY,
170166
},
171167
() => this.checkForMagicComments( compilation )
172168
);
173169
compilation.hooks.processAssets.tap(
174170
{
175171
name: this.constructor.name,
176-
stage: compiler.webpack.Compilation
177-
.PROCESS_ASSETS_STAGE_ANALYSE,
172+
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ANALYSE,
178173
},
179174
() => this.addAssets( compilation )
180175
);
@@ -247,6 +242,10 @@ class DependencyExtractionWebpackPlugin {
247242
outputFilename,
248243
} = this.options;
249244

245+
const { webpack } = compilation.compiler;
246+
const { RawSource } = webpack.sources;
247+
const { createHash } = webpack.util;
248+
250249
// Dump actually externalized dependencies to a report file.
251250
if ( externalizedReport ) {
252251
const externalizedReportFile =
@@ -493,6 +492,9 @@ class DependencyExtractionWebpackPlugin {
493492
return true;
494493
}
495494

495+
const { webpack } = compilation.compiler;
496+
const { AsyncDependenciesBlock } = webpack;
497+
496498
const staticDependentModules = incomingConnections.flatMap(
497499
( connection ) => {
498500
const { dependency } = connection;

0 commit comments

Comments
 (0)