You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
DependencyExtractionWebpackPlugin: Throw when using scripts from modules (#57795)
WordPress Script dependencies are not currently available as dependencies of WordPress Modules. Using e.g. lodash or @wordpress/api-fetch in a module build would result in bundling that dependency. For a package like lodash that's undesirable but should work. However, many @wordpress/* packages are not intended to be bundle or duplicated and will not work as expected.
It's likely an error to use WordPress Scripts inside modules at this time.
---------
Co-authored-by: Luis Herranz <[email protected]>
Copy file name to clipboardexpand all lines: packages/dependency-extraction-webpack-plugin/lib/util.js
+14-2
Original file line number
Diff line number
Diff line change
@@ -61,9 +61,13 @@ function defaultRequestToExternal( request ) {
61
61
*
62
62
* Currently only @wordpress/interactivity
63
63
*
64
+
* Do not use the boolean shorthand here, it's only handled for the `requestToExternalModule` option.
65
+
*
64
66
* @param {string} request Module request (the module name in `import from`) to be transformed
65
-
* @return {string|undefined} The resulting external definition. Return `undefined`
66
-
* to ignore the request. Return `string` to map the request to an external. This may simply be returning the request, e.g. `@wordpress/interactivity` maps to the external `@wordpress/interactivity`.
67
+
* @return {string|Error|undefined} The resulting external definition.
68
+
* - Return `undefined` to ignore the request (do not externalize).
69
+
* - Return `string` to map the request to an external.
70
+
* - Return `Error` to emit an error.
67
71
*/
68
72
functiondefaultRequestToExternalModule(request){
69
73
if(request==='@wordpress/interactivity'){
@@ -73,6 +77,14 @@ function defaultRequestToExternalModule( request ) {
73
77
// which forces @wordpress/interactivity imports to be hoisted to static imports.
Copy file name to clipboardexpand all lines: packages/dependency-extraction-webpack-plugin/test/__snapshots__/build.js.snap
+86-13
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
// Jest Snapshot v1, https://goo.gl/fbAQLP
2
2
3
3
exports[`DependencyExtractionWebpackPlugin modules Webpack \`combine-assets\` should produce expected output: Asset file 'assets.php' should match snapshot 1`] =`
@@ -17,6 +17,11 @@ exports[`DependencyExtractionWebpackPlugin modules Webpack \`combine-assets\` sh
17
17
"request": "@wordpress/token-list",
18
18
"userRequest": "@wordpress/token-list",
19
19
},
20
+
{
21
+
"externalType": "import",
22
+
"request": "lodash",
23
+
"userRequest": "lodash",
24
+
},
20
25
]
21
26
`;
22
27
@@ -65,8 +70,17 @@ exports[`DependencyExtractionWebpackPlugin modules Webpack \`dynamic-import\` sh
65
70
]
66
71
`;
67
72
73
+
exports[`DependencyExtractionWebpackPlugin modules Webpack \`error\` should produce expected output 1`] =`
74
+
"ERROR in ./index.js 5:0-23
75
+
Module not found: Error: Attempted to use WordPress script in a module: jquery, which is not supported yet.
76
+
77
+
ERROR in ./index.js 6:23-55
78
+
Module not found: Error: Attempted to use WordPress script in a module: @wordpress/api-fetch, which is not supported yet.
79
+
"
80
+
`;
81
+
68
82
exports[`DependencyExtractionWebpackPlugin modules Webpack \`function-output-filename\` should produce expected output: Asset file 'chunk--main--main.asset.php' should match snapshot 1`] =`
exports[`DependencyExtractionWebpackPlugin modules Webpack \`has-extension-suffix\` should produce expected output: Asset file 'index.min.asset.php' should match snapshot 1`] =`
@@ -130,7 +154,7 @@ exports[`DependencyExtractionWebpackPlugin modules Webpack \`no-deps\` should pr
130
154
exports[`DependencyExtractionWebpackPlugin modules Webpack \`no-deps\` should produce expected output: External modules should match snapshot 1`] =`[]`;
131
155
132
156
exports[`DependencyExtractionWebpackPlugin modules Webpack \`option-function-output-filename\` should produce expected output: Asset file 'chunk--main--main.asset.php' should match snapshot 1`] =`
exports[`DependencyExtractionWebpackPlugin modules Webpack \`option-output-filename\` should produce expected output: Asset file 'main-foo.asset.php' should match snapshot 1`] =`
exports[`DependencyExtractionWebpackPlugin modules Webpack \`output-format-json\` should produce expected output: Asset file 'main.asset.json' should match snapshot 1`] =`"{"dependencies":[],"version":"34504aa793c63cd3d73a","type":"module"}"`;
196
+
exports[`DependencyExtractionWebpackPlugin modules Webpack \`output-format-json\` should produce expected output: Asset file 'main.asset.json' should match snapshot 1`] =`"{"dependencies":["lodash"],"version":"4e62c01516f9dab8041f","type":"module"}"`;
163
197
164
-
exports[`DependencyExtractionWebpackPlugin modules Webpack \`output-format-json\` should produce expected output: External modules should match snapshot 1`] =`[]`;
198
+
exports[`DependencyExtractionWebpackPlugin modules Webpack \`output-format-json\` should produce expected output: External modules should match snapshot 1`] =`
199
+
[
200
+
{
201
+
"externalType": "import",
202
+
"request": "lodash",
203
+
"userRequest": "lodash",
204
+
},
205
+
]
206
+
`;
165
207
166
208
exports[`DependencyExtractionWebpackPlugin modules Webpack \`overrides\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] =`
exports[`DependencyExtractionWebpackPlugin modules Webpack \`runtime-chunk-single\` should produce expected output: Asset file 'b.asset.php' should match snapshot 1`] =`
exports[`DependencyExtractionWebpackPlugin modules Webpack \`runtime-chunk-single\` should produce expected output: Asset file 'runtime.asset.php' should match snapshot 1`] =`
exports[`DependencyExtractionWebpackPlugin modules Webpack \`style-imports\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] =`
exports[`DependencyExtractionWebpackPlugin modules Webpack \`wordpress\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] =`
@@ -245,16 +297,26 @@ exports[`DependencyExtractionWebpackPlugin modules Webpack \`wordpress\` should
245
297
"request": "@wordpress/blob",
246
298
"userRequest": "@wordpress/blob",
247
299
},
300
+
{
301
+
"externalType": "import",
302
+
"request": "lodash",
303
+
"userRequest": "lodash",
304
+
},
248
305
]
249
306
`;
250
307
251
308
exports[`DependencyExtractionWebpackPlugin modules Webpack \`wordpress-interactivity\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] =`
exports[`DependencyExtractionWebpackPlugin modules Webpack \`wordpress-interactivity\` should produce expected output: External modules should match snapshot 1`] =`
exports[`DependencyExtractionWebpackPlugin modules Webpack \`wordpress-require\` should produce expected output: Asset file 'main.asset.php' should match snapshot 1`] =`
@@ -363,6 +430,12 @@ exports[`DependencyExtractionWebpackPlugin scripts Webpack \`dynamic-import\` sh
363
430
]
364
431
`;
365
432
433
+
exports[`DependencyExtractionWebpackPlugin scripts Webpack \`error\` should produce expected output 1`] =`
434
+
"ERROR in main
435
+
Module not found: Error: Ensure error in script build.
436
+
"
437
+
`;
438
+
366
439
exports[`DependencyExtractionWebpackPlugin scripts Webpack \`function-output-filename\` should produce expected output: Asset file 'chunk--main--main.asset.php' should match snapshot 1`] =`
0 commit comments