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
Copy file name to clipboardExpand all lines: packages/dependency-extraction-webpack-plugin/lib/index.js
+103-10
Original file line number
Diff line number
Diff line change
@@ -2,10 +2,12 @@
2
2
* External dependencies
3
3
*/
4
4
const{ createHash }=require('crypto');
5
-
constjson2php=require('json2php');
6
5
constpath=require('path');
7
6
const{ ExternalsPlugin }=require('webpack');
8
7
const{ RawSource }=require('webpack-sources');
8
+
// Ignore reason: json2php is untyped
9
+
// @ts-ignore
10
+
constjson2php=require('json2php');
9
11
10
12
/**
11
13
* Internal dependencies
@@ -15,8 +17,53 @@ const {
15
17
defaultRequestToHandle,
16
18
}=require('./util');
17
19
20
+
/**
21
+
* Map module request to an external.
22
+
*
23
+
* @callback RequestToExternal
24
+
*
25
+
* @param {string} request Module request.
26
+
*
27
+
* @return {string|string[]|void} Return `undefined` to ignore the request.
28
+
* Return `string|string[]` to map the request to an external.
29
+
*/
30
+
31
+
/**
32
+
* Map module request to a script handle.
33
+
*
34
+
* @callback RequestToHandle
35
+
*
36
+
* @param {string} request Module request.
37
+
*
38
+
* @return {string|void} Return `undefined` to use the same name as the module.
39
+
* Return `string` to map the request to a specific script handle.
40
+
*/
41
+
42
+
/**
43
+
* @typedef AssetData
44
+
*
45
+
* @property {string} version String representing a particular build
46
+
* @property {string[]} dependencies The script dependencies
47
+
*/
48
+
49
+
/**
50
+
* @typedef Options
51
+
*
52
+
* @property {boolean} injectPolyfill Force wp-polyfill to be included in each entry point's dependency list. This is like importing `@wordpress/polyfill` for each entry point.
53
+
* @property {boolean} useDefaults Set to `false` to disable the default WordPress script request handling.
54
+
* @property {'php'|'json'} outputFormat The output format for the generated asset file.
55
+
* @property {RequestToExternal|undefined} [requestToExternal] Map module requests to an external.
56
+
* @property {RequestToHandle|undefined} [requestToHandle] Map module requests to a script handle.
57
+
* @property {string|null} combinedOutputFile This option is useful only when the combineAssets option is enabled. It allows providing a custom output file for the generated single assets file. It's possible to provide a path that is relative to the output directory.
58
+
* @property {boolean|undefined} combineAssets By default, one asset file is created for each entry point. When this flag is set to true, all information about assets is combined into a single assets.(json|php) file generated in the output directory.
59
+
*/
60
+
18
61
classDependencyExtractionWebpackPlugin{
62
+
/**
63
+
* @param {Partial<Options>} options
64
+
*/
19
65
constructor(options){
66
+
/** @type {Options} */
20
67
this.options=Object.assign(
21
68
{
22
69
combineAssets: false,
@@ -28,11 +75,15 @@ class DependencyExtractionWebpackPlugin {
28
75
options
29
76
);
30
77
31
-
// Track requests that are externalized.
32
-
//
33
-
// Because we don't have a closed set of dependencies, we need to track what has
34
-
// been externalized so we can recognize them in a later phase when the dependency
35
-
// lists are generated.
78
+
/**
79
+
* Track requests that are externalized.
80
+
*
81
+
* Because we don't have a closed set of dependencies, we need to track what has
82
+
* been externalized so we can recognize them in a later phase when the dependency
83
+
* lists are generated.
84
+
*
85
+
* @type {Set<string>}
86
+
*/
36
87
this.externalizedDeps=newSet();
37
88
38
89
// Offload externalization work to the ExternalsPlugin.
@@ -42,7 +93,14 @@ class DependencyExtractionWebpackPlugin {
0 commit comments