Skip to content

Commit e4f147e

Browse files
committed
Improve requestToExternalModule shorthand handling
1 parent e018681 commit e4f147e

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

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

+12-5
Original file line numberDiff line numberDiff line change
@@ -67,22 +67,29 @@ class DependencyExtractionWebpackPlugin {
6767
if ( typeof this.options.requestToExternalModule === 'function' ) {
6868
externalRequest =
6969
this.options.requestToExternalModule( request );
70+
71+
// requestToExternalModule allows a boolean shorthand
72+
if ( externalRequest === false ) {
73+
externalRequest = undefined;
74+
}
75+
if ( externalRequest === true ) {
76+
externalRequest = request;
77+
}
7078
}
7179
} else if ( typeof this.options.requestToExternal === 'function' ) {
7280
externalRequest = this.options.requestToExternal( request );
7381
}
7482

7583
// Cascade to default if unhandled and enabled.
76-
if ( ! externalRequest && this.options.useDefaults ) {
84+
if (
85+
typeof externalRequest === 'undefined' &&
86+
this.options.useDefaults
87+
) {
7788
externalRequest = this.useModules
7889
? defaultRequestToExternalModule( request )
7990
: defaultRequestToExternal( request );
8091
}
8192

82-
if ( this.useModules && externalRequest === true ) {
83-
externalRequest = request;
84-
}
85-
8693
if ( externalRequest instanceof Error ) {
8794
return callback( externalRequest );
8895
}

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,11 @@ function defaultRequestToExternal( request ) {
6161
*
6262
* Currently only @wordpress/interactivity
6363
*
64+
* Do not use the boolean shorthand here, it's only handled for the `requestToExternalModule` option.
65+
*
6466
* @param {string} request Module request (the module name in `import from`) to be transformed
65-
* @return {string|boolean|Error|undefined} The resulting external definition.
67+
* @return {string|Error|undefined} The resulting external definition.
6668
* - Return `undefined` to ignore the request (do not externalize).
67-
* - Return `true` to externalize the request with the same Module ID
6869
* - Return `string` to map the request to an external.
6970
* - Return `Error` to emit an error.
7071
*/

0 commit comments

Comments
 (0)