webpack 4.8.2 → 4.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -52
- package/bin/webpack.js +128 -43
- package/lib/AmdMainTemplatePlugin.js +10 -0
- package/lib/AsyncDependencyToInitialChunkError.js +12 -2
- package/lib/BannerPlugin.js +115 -101
- package/lib/CaseSensitiveModulesWarning.js +20 -2
- package/lib/Chunk.js +1 -0
- package/lib/ChunkGroup.js +465 -465
- package/lib/ChunkRenderError.js +8 -0
- package/lib/ChunkTemplate.js +71 -71
- package/lib/Compilation.js +1 -1
- package/lib/Compiler.js +2 -1
- package/lib/ContextModule.js +8 -8
- package/lib/DllPlugin.js +3 -1
- package/lib/DllReferencePlugin.js +2 -1
- package/lib/Entrypoint.js +54 -54
- package/lib/EvalSourceMapDevToolModuleTemplatePlugin.js +115 -115
- package/lib/ExportPropertyMainTemplatePlugin.js +13 -0
- package/lib/Generator.js +52 -52
- package/lib/HotModuleReplacement.runtime.js +633 -633
- package/lib/JsonParser.js +2 -1
- package/lib/LibManifestPlugin.js +9 -0
- package/lib/LibraryTemplatePlugin.js +66 -33
- package/lib/MainTemplate.js +468 -468
- package/lib/Module.js +3 -3
- package/lib/ModuleDependencyError.js +12 -2
- package/lib/NormalModuleFactory.js +5 -3
- package/lib/Parser.js +27 -23
- package/lib/ProgressPlugin.js +1 -1
- package/lib/RecordIdsPlugin.js +3 -1
- package/lib/RuntimeTemplate.js +1 -1
- package/lib/SetVarMainTemplatePlugin.js +12 -0
- package/lib/SourceMapDevToolPlugin.js +11 -13
- package/lib/Template.js +289 -290
- package/lib/UmdMainTemplatePlugin.js +67 -32
- package/lib/WebpackError.js +8 -2
- package/lib/compareLocations.js +20 -0
- package/lib/debug/ProfilingPlugin.js +416 -416
- package/lib/dependencies/ContextDependencyHelpers.js +142 -142
- package/lib/dependencies/WebpackMissingModule.js +2 -2
- package/lib/optimize/RemoveEmptyChunksPlugin.js +42 -40
- package/lib/optimize/RuntimeChunkPlugin.js +9 -5
- package/lib/optimize/SplitChunksPlugin.js +195 -124
- package/lib/util/Queue.js +46 -46
- package/lib/util/SetHelpers.js +48 -48
- package/lib/util/SortableSet.js +106 -106
- package/lib/util/StackedSetMap.js +128 -128
- package/lib/util/cachedMerge.js +13 -0
- package/lib/util/identifier.js +5 -0
- package/lib/util/objectToMap.js +16 -16
- package/lib/wasm/WebAssemblyGenerator.js +280 -280
- package/lib/wasm/WebAssemblyParser.js +79 -79
- package/lib/web/JsonpMainTemplatePlugin.js +2 -2
- package/package.json +21 -17
- package/schemas/WebpackOptions.json +12 -1
- package/schemas/plugins/BannerPlugin.json +96 -85
- package/schemas/plugins/DllPlugin.json +4 -0
package/lib/Template.js
CHANGED
@@ -1,290 +1,289 @@
|
|
1
|
-
/*
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
-
Author Tobias Koppers @sokra
|
4
|
-
*/
|
5
|
-
/** @typedef {import("./Module")} Module */
|
6
|
-
/** @typedef {import("./Chunk")} Chunk */
|
7
|
-
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
8
|
-
/** @typedef {import("webpack-sources").ConcatSource} ConcatSource */
|
9
|
-
|
10
|
-
const { ConcatSource } = require("webpack-sources");
|
11
|
-
const HotUpdateChunk = require("./HotUpdateChunk");
|
12
|
-
|
13
|
-
const START_LOWERCASE_ALPHABET_CODE = "a".charCodeAt(0);
|
14
|
-
const START_UPPERCASE_ALPHABET_CODE = "A".charCodeAt(0);
|
15
|
-
const DELTA_A_TO_Z = "z".charCodeAt(0) - START_LOWERCASE_ALPHABET_CODE + 1;
|
16
|
-
const FUNCTION_CONTENT_REGEX = /^function\s?\(\)\s?\{\r?\n?|\r?\n?\}$/g;
|
17
|
-
const INDENT_MULTILINE_REGEX = /^\t/gm;
|
18
|
-
const LINE_SEPARATOR_REGEX = /\r?\n/g;
|
19
|
-
const IDENTIFIER_NAME_REPLACE_REGEX = /^([^a-zA-Z$_])/;
|
20
|
-
const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = /[^a-zA-Z0-9$]+/g;
|
21
|
-
const COMMENT_END_REGEX = /\*\//g;
|
22
|
-
const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-zA-Z0-9_!§$()=\-^°]+/g;
|
23
|
-
const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
24
|
-
|
25
|
-
/**
|
26
|
-
* @typedef {Object} HasId
|
27
|
-
* @property {number} id
|
28
|
-
* */
|
29
|
-
|
30
|
-
/**
|
31
|
-
* @typedef {(m: Module, idx: number) => boolean} ModuleFilterPredicate
|
32
|
-
*/
|
33
|
-
|
34
|
-
/**
|
35
|
-
* @param {HasId} a first id object to be sorted
|
36
|
-
* @param {HasId} b second id object to be sorted against
|
37
|
-
* @returns {-1|0|1} the sort value
|
38
|
-
*/
|
39
|
-
const stringifyIdSortPredicate = (a, b) => {
|
40
|
-
var aId = a.id + "";
|
41
|
-
var bId = b.id + "";
|
42
|
-
if (aId < bId) return -1;
|
43
|
-
if (aId > bId) return 1;
|
44
|
-
return 0;
|
45
|
-
};
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
*
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
.
|
66
|
-
.replace(
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
*
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
*
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
*
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
*
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
*
|
152
|
-
* @
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
*
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
*
|
180
|
-
*
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
if (!modules.every(moduleIdIsNumber)) return false;
|
186
|
-
var maxId = -Infinity;
|
187
|
-
var minId = Infinity;
|
188
|
-
for (const module of modules) {
|
189
|
-
if (maxId < module.id) maxId = module.id;
|
190
|
-
if (minId > module.id) minId = module.id;
|
191
|
-
}
|
192
|
-
if (minId < 16 + ("" + minId).length) {
|
193
|
-
// add minId x ',' instead of 'Array(minId).concat(…)'
|
194
|
-
minId = 0;
|
195
|
-
}
|
196
|
-
var objectOverhead = modules
|
197
|
-
.map(module => {
|
198
|
-
var idLength = (module.id + "").length;
|
199
|
-
return idLength + 2;
|
200
|
-
})
|
201
|
-
.reduce((a, b) => {
|
202
|
-
return a + b;
|
203
|
-
}, -1);
|
204
|
-
var arrayOverhead = minId === 0 ? maxId : 16 + ("" + minId).length + maxId;
|
205
|
-
return arrayOverhead < objectOverhead ? [minId, maxId] : false;
|
206
|
-
}
|
207
|
-
|
208
|
-
/**
|
209
|
-
*
|
210
|
-
* @param {
|
211
|
-
* @param {
|
212
|
-
* @param {
|
213
|
-
* @param {
|
214
|
-
* @
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
source
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
var
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
const
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
source.add(
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
source.add("
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
source.add(
|
282
|
-
|
283
|
-
});
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
module.exports = Template;
|
1
|
+
/*
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
3
|
+
Author Tobias Koppers @sokra
|
4
|
+
*/
|
5
|
+
/** @typedef {import("./Module")} Module */
|
6
|
+
/** @typedef {import("./Chunk")} Chunk */
|
7
|
+
/** @typedef {import("./ModuleTemplate")} ModuleTemplate */
|
8
|
+
/** @typedef {import("webpack-sources").ConcatSource} ConcatSource */
|
9
|
+
|
10
|
+
const { ConcatSource } = require("webpack-sources");
|
11
|
+
const HotUpdateChunk = require("./HotUpdateChunk");
|
12
|
+
|
13
|
+
const START_LOWERCASE_ALPHABET_CODE = "a".charCodeAt(0);
|
14
|
+
const START_UPPERCASE_ALPHABET_CODE = "A".charCodeAt(0);
|
15
|
+
const DELTA_A_TO_Z = "z".charCodeAt(0) - START_LOWERCASE_ALPHABET_CODE + 1;
|
16
|
+
const FUNCTION_CONTENT_REGEX = /^function\s?\(\)\s?\{\r?\n?|\r?\n?\}$/g;
|
17
|
+
const INDENT_MULTILINE_REGEX = /^\t/gm;
|
18
|
+
const LINE_SEPARATOR_REGEX = /\r?\n/g;
|
19
|
+
const IDENTIFIER_NAME_REPLACE_REGEX = /^([^a-zA-Z$_])/;
|
20
|
+
const IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX = /[^a-zA-Z0-9$]+/g;
|
21
|
+
const COMMENT_END_REGEX = /\*\//g;
|
22
|
+
const PATH_NAME_NORMALIZE_REPLACE_REGEX = /[^a-zA-Z0-9_!§$()=\-^°]+/g;
|
23
|
+
const MATCH_PADDED_HYPHENS_REPLACE_REGEX = /^-|-$/g;
|
24
|
+
|
25
|
+
/**
|
26
|
+
* @typedef {Object} HasId
|
27
|
+
* @property {number} id
|
28
|
+
* */
|
29
|
+
|
30
|
+
/**
|
31
|
+
* @typedef {(m: Module, idx: number) => boolean} ModuleFilterPredicate
|
32
|
+
*/
|
33
|
+
|
34
|
+
/**
|
35
|
+
* @param {HasId} a first id object to be sorted
|
36
|
+
* @param {HasId} b second id object to be sorted against
|
37
|
+
* @returns {-1|0|1} the sort value
|
38
|
+
*/
|
39
|
+
const stringifyIdSortPredicate = (a, b) => {
|
40
|
+
var aId = a.id + "";
|
41
|
+
var bId = b.id + "";
|
42
|
+
if (aId < bId) return -1;
|
43
|
+
if (aId > bId) return 1;
|
44
|
+
return 0;
|
45
|
+
};
|
46
|
+
|
47
|
+
/**
|
48
|
+
* @param {Module} module the module to compare against
|
49
|
+
* @returns {boolean} return true if module.id is equal to type "number"
|
50
|
+
*/
|
51
|
+
const moduleIdIsNumber = module => {
|
52
|
+
return typeof module.id === "number";
|
53
|
+
};
|
54
|
+
|
55
|
+
class Template {
|
56
|
+
/**
|
57
|
+
*
|
58
|
+
* @param {Function} fn - a runtime function (.runtime.js) "template"
|
59
|
+
* @returns {string} the updated and normalized function string
|
60
|
+
*/
|
61
|
+
static getFunctionContent(fn) {
|
62
|
+
return fn
|
63
|
+
.toString()
|
64
|
+
.replace(FUNCTION_CONTENT_REGEX, "")
|
65
|
+
.replace(INDENT_MULTILINE_REGEX, "")
|
66
|
+
.replace(LINE_SEPARATOR_REGEX, "\n");
|
67
|
+
}
|
68
|
+
/**
|
69
|
+
* @param {string} str the string converted to identifier
|
70
|
+
* @returns {string} created identifier
|
71
|
+
*/
|
72
|
+
static toIdentifier(str) {
|
73
|
+
if (typeof str !== "string") return "";
|
74
|
+
return str
|
75
|
+
.replace(IDENTIFIER_NAME_REPLACE_REGEX, "_$1")
|
76
|
+
.replace(IDENTIFIER_ALPHA_NUMERIC_NAME_REPLACE_REGEX, "_");
|
77
|
+
}
|
78
|
+
/**
|
79
|
+
*
|
80
|
+
* @param {string} str string to be converted to commented in bundle code
|
81
|
+
* @returns {string} returns a commented version of string
|
82
|
+
*/
|
83
|
+
static toComment(str) {
|
84
|
+
if (!str) return "";
|
85
|
+
return `/*! ${str.replace(COMMENT_END_REGEX, "* /")} */`;
|
86
|
+
}
|
87
|
+
|
88
|
+
/**
|
89
|
+
*
|
90
|
+
* @param {string} str string to be converted to "normal comment"
|
91
|
+
* @returns {string} returns a commented version of string
|
92
|
+
*/
|
93
|
+
static toNormalComment(str) {
|
94
|
+
if (!str) return "";
|
95
|
+
return `/* ${str.replace(COMMENT_END_REGEX, "* /")} */`;
|
96
|
+
}
|
97
|
+
|
98
|
+
/**
|
99
|
+
* @param {string} str string path to be normalized
|
100
|
+
* @returns {string} normalized bundle-safe path
|
101
|
+
*/
|
102
|
+
static toPath(str) {
|
103
|
+
if (typeof str !== "string") return "";
|
104
|
+
return str
|
105
|
+
.replace(PATH_NAME_NORMALIZE_REPLACE_REGEX, "-")
|
106
|
+
.replace(MATCH_PADDED_HYPHENS_REPLACE_REGEX, "");
|
107
|
+
}
|
108
|
+
|
109
|
+
// map number to a single character a-z, A-Z or <_ + number> if number is too big
|
110
|
+
/**
|
111
|
+
*
|
112
|
+
* @param {number} n number to convert to ident
|
113
|
+
* @returns {string} returns single character ident
|
114
|
+
*/
|
115
|
+
static numberToIdentifer(n) {
|
116
|
+
// lower case
|
117
|
+
if (n < DELTA_A_TO_Z)
|
118
|
+
return String.fromCharCode(START_LOWERCASE_ALPHABET_CODE + n);
|
119
|
+
|
120
|
+
// upper case
|
121
|
+
n -= DELTA_A_TO_Z;
|
122
|
+
if (n < DELTA_A_TO_Z)
|
123
|
+
return String.fromCharCode(START_UPPERCASE_ALPHABET_CODE + n);
|
124
|
+
|
125
|
+
// use multiple letters
|
126
|
+
return (
|
127
|
+
Template.numberToIdentifer(n % (2 * DELTA_A_TO_Z)) +
|
128
|
+
Template.numberToIdentifer(Math.floor(n / (2 * DELTA_A_TO_Z)))
|
129
|
+
);
|
130
|
+
}
|
131
|
+
|
132
|
+
/**
|
133
|
+
*
|
134
|
+
* @param {string | string[]} str string to convert to identity
|
135
|
+
* @returns {string} converted identity
|
136
|
+
*/
|
137
|
+
static indent(str) {
|
138
|
+
if (Array.isArray(str)) {
|
139
|
+
return str.map(Template.indent).join("\n");
|
140
|
+
} else {
|
141
|
+
str = str.trimRight();
|
142
|
+
if (!str) return "";
|
143
|
+
var ind = str[0] === "\n" ? "" : "\t";
|
144
|
+
return ind + str.replace(/\n([^\n])/g, "\n\t$1");
|
145
|
+
}
|
146
|
+
}
|
147
|
+
|
148
|
+
/**
|
149
|
+
*
|
150
|
+
* @param {string|string[]} str string to create prefix for
|
151
|
+
* @param {string} prefix prefix to compose
|
152
|
+
* @returns {string} returns new prefix string
|
153
|
+
*/
|
154
|
+
static prefix(str, prefix) {
|
155
|
+
if (Array.isArray(str)) {
|
156
|
+
str = str.join("\n");
|
157
|
+
}
|
158
|
+
str = str.trim();
|
159
|
+
if (!str) return "";
|
160
|
+
const ind = str[0] === "\n" ? "" : prefix;
|
161
|
+
return ind + str.replace(/\n([^\n])/g, "\n" + prefix + "$1");
|
162
|
+
}
|
163
|
+
|
164
|
+
/**
|
165
|
+
*
|
166
|
+
* @param {string|string[]} str string or string collection
|
167
|
+
* @returns {string} returns a single string from array
|
168
|
+
*/
|
169
|
+
static asString(str) {
|
170
|
+
if (Array.isArray(str)) {
|
171
|
+
return str.join("\n");
|
172
|
+
}
|
173
|
+
return str;
|
174
|
+
}
|
175
|
+
|
176
|
+
/**
|
177
|
+
*
|
178
|
+
* @param {Module[]} modules a collection of modules to get array bounds for
|
179
|
+
* @returns {[number, number] | false} returns the upper and lower array bounds
|
180
|
+
* or false if not every module has a number based id
|
181
|
+
*/
|
182
|
+
static getModulesArrayBounds(modules) {
|
183
|
+
// Typeguards don't work for .every() with predicate functions
|
184
|
+
// https://github.com/Microsoft/TypeScript/issues/23799
|
185
|
+
if (!modules.every(moduleIdIsNumber)) return false;
|
186
|
+
var maxId = -Infinity;
|
187
|
+
var minId = Infinity;
|
188
|
+
for (const module of modules) {
|
189
|
+
if (maxId < module.id) maxId = /** @type {number} */ (module.id);
|
190
|
+
if (minId > module.id) minId = /** @type {number} */ (module.id);
|
191
|
+
}
|
192
|
+
if (minId < 16 + ("" + minId).length) {
|
193
|
+
// add minId x ',' instead of 'Array(minId).concat(…)'
|
194
|
+
minId = 0;
|
195
|
+
}
|
196
|
+
var objectOverhead = modules
|
197
|
+
.map(module => {
|
198
|
+
var idLength = (module.id + "").length;
|
199
|
+
return idLength + 2;
|
200
|
+
})
|
201
|
+
.reduce((a, b) => {
|
202
|
+
return a + b;
|
203
|
+
}, -1);
|
204
|
+
var arrayOverhead = minId === 0 ? maxId : 16 + ("" + minId).length + maxId;
|
205
|
+
return arrayOverhead < objectOverhead ? [minId, maxId] : false;
|
206
|
+
}
|
207
|
+
|
208
|
+
/**
|
209
|
+
* @param {Chunk} chunk chunk whose modules will be rendered
|
210
|
+
* @param {ModuleFilterPredicate} filterFn function used to filter modules from chunk to render
|
211
|
+
* @param {ModuleTemplate} moduleTemplate ModuleTemplate instance used to render modules
|
212
|
+
* @param {TODO | TODO[]} dependencyTemplates templates needed for each module to render dependencies
|
213
|
+
* @param {string=} prefix applying prefix strings
|
214
|
+
* @returns {ConcatSource} rendered chunk modules in a Source object
|
215
|
+
*/
|
216
|
+
static renderChunkModules(
|
217
|
+
chunk,
|
218
|
+
filterFn,
|
219
|
+
moduleTemplate,
|
220
|
+
dependencyTemplates,
|
221
|
+
prefix
|
222
|
+
) {
|
223
|
+
if (!prefix) prefix = "";
|
224
|
+
var source = new ConcatSource();
|
225
|
+
const modules = chunk.getModules().filter(filterFn);
|
226
|
+
if (chunk instanceof HotUpdateChunk) {
|
227
|
+
var removedModules = chunk.removedModules;
|
228
|
+
}
|
229
|
+
if (
|
230
|
+
modules.length === 0 &&
|
231
|
+
(!removedModules || removedModules.length === 0)
|
232
|
+
) {
|
233
|
+
source.add("[]");
|
234
|
+
return source;
|
235
|
+
}
|
236
|
+
var allModules = modules.map(module => {
|
237
|
+
return {
|
238
|
+
id: module.id,
|
239
|
+
source: moduleTemplate.render(module, dependencyTemplates, {
|
240
|
+
chunk
|
241
|
+
})
|
242
|
+
};
|
243
|
+
});
|
244
|
+
if (removedModules && removedModules.length > 0) {
|
245
|
+
for (const id of removedModules) {
|
246
|
+
allModules.push({
|
247
|
+
id: id,
|
248
|
+
source: "false"
|
249
|
+
});
|
250
|
+
}
|
251
|
+
}
|
252
|
+
var bounds = Template.getModulesArrayBounds(allModules);
|
253
|
+
|
254
|
+
if (bounds) {
|
255
|
+
// Render a spare array
|
256
|
+
var minId = bounds[0];
|
257
|
+
var maxId = bounds[1];
|
258
|
+
if (minId !== 0) source.add("Array(" + minId + ").concat(");
|
259
|
+
source.add("[\n");
|
260
|
+
const modules = new Map();
|
261
|
+
for (const module of allModules) {
|
262
|
+
modules.set(module.id, module);
|
263
|
+
}
|
264
|
+
for (var idx = minId; idx <= maxId; idx++) {
|
265
|
+
var module = modules.get(idx);
|
266
|
+
if (idx !== minId) source.add(",\n");
|
267
|
+
source.add("/* " + idx + " */");
|
268
|
+
if (module) {
|
269
|
+
source.add("\n");
|
270
|
+
source.add(module.source);
|
271
|
+
}
|
272
|
+
}
|
273
|
+
source.add("\n" + prefix + "]");
|
274
|
+
if (minId !== 0) source.add(")");
|
275
|
+
} else {
|
276
|
+
// Render an object
|
277
|
+
source.add("{\n");
|
278
|
+
allModules.sort(stringifyIdSortPredicate).forEach((module, idx) => {
|
279
|
+
if (idx !== 0) source.add(",\n");
|
280
|
+
source.add(`\n/***/ ${JSON.stringify(module.id)}:\n`);
|
281
|
+
source.add(module.source);
|
282
|
+
});
|
283
|
+
source.add("\n\n" + prefix + "}");
|
284
|
+
}
|
285
|
+
return source;
|
286
|
+
}
|
287
|
+
}
|
288
|
+
|
289
|
+
module.exports = Template;
|