Skip to content

Commit 8636670

Browse files
committed
Revert "Add output.entryPrefetchFunction option, and don't immediately prefetch"
This reverts commit b642403.
1 parent 6d85e8d commit 8636670

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

lib/WebpackOptionsDefaulter.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,6 @@ class WebpackOptionsDefaulter extends OptionsDefaulter {
161161
this.set("output.hashDigestLength", 20);
162162
this.set("output.devtoolLineToLine", false);
163163
this.set("output.strictModuleExceptionHandling", false);
164-
this.set("output.entryPrefetchFunction", "make", options => {
165-
return Template.toIdentifier(
166-
"webpackEntryPrefetch" + Template.toIdentifier(options.output.library)
167-
);
168-
});
169164

170165
this.set("node", "call", value => {
171166
if (typeof value === "boolean") {

lib/web/JsonpMainTemplatePlugin.js

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class JsonpMainTemplatePlugin {
114114
});
115115
};
116116

117-
const linkPreload = () => {
117+
const linkPreload = mainTemplate => {
118118
const crossOriginLoading = mainTemplate.outputOptions.crossOriginLoading;
119119
const jsonpScriptType = mainTemplate.outputOptions.jsonpScriptType;
120120
return Template.asString([
@@ -181,19 +181,16 @@ class JsonpMainTemplatePlugin {
181181
}
182182
if (needEntryChunkPrefetch(chunk)) {
183183
let preloadPrefetchChildren = chunk.getChildIdsByOrders();
184-
let entryPrefetchFunction = mainTemplate.outputOptions.entryPrefetchFunction;
185-
let globalObject = mainTemplate.outputOptions.globalObject;
186-
187184
extraCode.push(
188185
"",
189186
"// preload or prefetch split chunks from entry chunk",
190-
`${globalObject}['${entryPrefetchFunction}'] = () => {`,
187+
"(function prefetchOrPreloadFromEntry() {",
191188
preloadPrefetchChildren.preload
192189
? Template.indent([
193190
`${JSON.stringify(
194191
preloadPrefetchChildren.preload
195192
)}.map(chunkId => {`,
196-
Template.indent([linkPreload()]),
193+
Template.indent([linkPreload(mainTemplate)]),
197194
`});`
198195
])
199196
: "",
@@ -206,7 +203,7 @@ class JsonpMainTemplatePlugin {
206203
`});`
207204
])
208205
: "",
209-
"}",
206+
"})();"
210207
);
211208
}
212209
if (extraCode.length === 0) return source;
@@ -274,7 +271,7 @@ class JsonpMainTemplatePlugin {
274271
mainTemplate.hooks.linkPreload.tap(
275272
"JsonpMainTemplatePlugin",
276273
(_, chunk, hash) => {
277-
return linkPreload();
274+
return linkPreload(mainTemplate);
278275
}
279276
);
280277
mainTemplate.hooks.linkPrefetch.tap(

test/configCases/web/prefetch-preload/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ it("should prefetch and preload child chunks on chunk load", (done) => {
2121
__webpack_nonce__ = "nonce";
2222
__webpack_public_path__ = "/public/path/";
2323

24-
const promise = import(/* webpackChunkName: "chunk1", webpackPrefetch: true */ "./chunk1");
24+
const promise = import(/* webpackChunkName: "chunk1" */ "./chunk1");
2525
expect(document.head._children).toHaveLength(2);
2626
const script = document.head._children[0];
2727
expect(script._type).toBe("script");

0 commit comments

Comments
 (0)