2014-06-03 03:23:53 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2017-02-23 00:54:16 +08:00
|
|
|
"use strict";
|
2014-06-03 03:23:53 +08:00
|
|
|
|
2017-11-12 01:48:29 +08:00
|
|
|
const Template = require("../Template");
|
2017-11-29 01:43:01 +08:00
|
|
|
const SyncWaterfallHook = require("tapable").SyncWaterfallHook;
|
2014-06-03 03:23:53 +08:00
|
|
|
|
2017-02-23 00:54:16 +08:00
|
|
|
class JsonpMainTemplatePlugin {
|
2014-06-03 03:23:53 +08:00
|
|
|
|
2017-02-23 00:54:16 +08:00
|
|
|
apply(mainTemplate) {
|
2018-01-20 00:06:59 +08:00
|
|
|
const needChunkOnDemandLoadingCode = chunk => {
|
|
|
|
for(const chunkGroup of chunk.groupsIterable) {
|
|
|
|
if(chunkGroup.getNumberOfChildren() > 0) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
2017-11-08 18:32:05 +08:00
|
|
|
const needChunkLoadingCode = chunk => {
|
2018-01-20 00:06:59 +08:00
|
|
|
for(const chunkGroup of chunk.groupsIterable) {
|
|
|
|
if(chunkGroup.chunks.length > 1) return true;
|
|
|
|
if(chunkGroup.getNumberOfChildren() > 0) return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
const needEntryDeferringCode = chunk => {
|
|
|
|
for(const chunkGroup of chunk.groupsIterable) {
|
|
|
|
if(chunkGroup.chunks.length > 1) return true;
|
|
|
|
}
|
|
|
|
return false;
|
2017-11-08 18:32:05 +08:00
|
|
|
};
|
2017-11-29 01:43:01 +08:00
|
|
|
// TODO refactor this
|
2017-12-23 14:13:13 +08:00
|
|
|
if(!mainTemplate.hooks.jsonpScript) {
|
2017-11-29 01:43:01 +08:00
|
|
|
mainTemplate.hooks.jsonpScript = new SyncWaterfallHook(["source", "chunk", "hash"]);
|
2017-12-23 14:13:13 +08:00
|
|
|
}
|
|
|
|
|
2017-12-23 21:41:57 +08:00
|
|
|
mainTemplate.hooks.localVars.tap("JsonpMainTemplatePlugin", (source, chunk) => {
|
2017-04-23 00:59:15 +08:00
|
|
|
if(needChunkLoadingCode(chunk)) {
|
2017-12-07 16:42:33 +08:00
|
|
|
return Template.asString([
|
2017-02-23 00:54:16 +08:00
|
|
|
source,
|
|
|
|
"",
|
2017-10-30 20:56:57 +08:00
|
|
|
"// object to store loaded and loading chunks",
|
2017-02-23 00:54:16 +08:00
|
|
|
"var installedChunks = {",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent(
|
2017-02-23 00:54:16 +08:00
|
|
|
chunk.ids.map(id => `${JSON.stringify(id)}: 0`).join(",\n")
|
|
|
|
),
|
2017-04-23 00:59:15 +08:00
|
|
|
"};",
|
|
|
|
"",
|
2018-01-20 00:06:59 +08:00
|
|
|
needEntryDeferringCode(chunk) ? "var deferredModules = [];" : ""
|
2017-02-23 00:54:16 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
return source;
|
|
|
|
});
|
2017-12-23 14:13:13 +08:00
|
|
|
mainTemplate.hooks.jsonpScript.tap("JsonpMainTemplatePlugin", (_, chunk, hash) => {
|
2017-11-08 18:32:05 +08:00
|
|
|
const chunkFilename = mainTemplate.outputOptions.chunkFilename;
|
2017-02-23 00:54:16 +08:00
|
|
|
const chunkMaps = chunk.getChunkMaps();
|
2017-11-08 18:32:05 +08:00
|
|
|
const crossOriginLoading = mainTemplate.outputOptions.crossOriginLoading;
|
|
|
|
const chunkLoadTimeout = mainTemplate.outputOptions.chunkLoadTimeout;
|
2018-01-05 03:34:59 +08:00
|
|
|
const jsonpScriptType = mainTemplate.outputOptions.jsonpScriptType;
|
2017-11-29 01:43:01 +08:00
|
|
|
const scriptSrcPath = mainTemplate.getAssetPath(JSON.stringify(chunkFilename), {
|
2017-11-08 18:32:05 +08:00
|
|
|
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
|
|
|
|
hashWithLength: length => `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
|
2015-07-17 15:30:37 +08:00
|
|
|
chunk: {
|
|
|
|
id: "\" + chunkId + \"",
|
2017-03-07 16:33:43 +08:00
|
|
|
hash: `" + ${JSON.stringify(chunkMaps.hash)}[chunkId] + "`,
|
|
|
|
hashWithLength(length) {
|
|
|
|
const shortChunkHashMap = Object.create(null);
|
|
|
|
Object.keys(chunkMaps.hash).forEach(chunkId => {
|
2015-07-17 15:30:37 +08:00
|
|
|
if(typeof chunkMaps.hash[chunkId] === "string")
|
|
|
|
shortChunkHashMap[chunkId] = chunkMaps.hash[chunkId].substr(0, length);
|
|
|
|
});
|
2017-03-07 16:33:43 +08:00
|
|
|
return `" + ${JSON.stringify(shortChunkHashMap)}[chunkId] + "`;
|
2015-07-17 15:30:37 +08:00
|
|
|
},
|
2017-03-07 16:33:43 +08:00
|
|
|
name: `" + (${JSON.stringify(chunkMaps.name)}[chunkId]||chunkId) + "`
|
2015-07-17 15:30:37 +08:00
|
|
|
}
|
2017-03-07 16:33:43 +08:00
|
|
|
});
|
2017-12-07 16:42:33 +08:00
|
|
|
return Template.asString([
|
2017-02-23 00:54:16 +08:00
|
|
|
"var script = document.createElement('script');",
|
2018-01-05 03:34:59 +08:00
|
|
|
jsonpScriptType ? `script.type = ${JSON.stringify(jsonpScriptType)};` : "",
|
2017-02-23 00:54:16 +08:00
|
|
|
"script.charset = 'utf-8';",
|
|
|
|
`script.timeout = ${chunkLoadTimeout};`,
|
2017-02-28 22:34:46 +08:00
|
|
|
crossOriginLoading ? `script.crossOrigin = ${JSON.stringify(crossOriginLoading)};` : "",
|
2017-11-08 18:32:05 +08:00
|
|
|
`if (${mainTemplate.requireFn}.nc) {`,
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent(`script.setAttribute("nonce", ${mainTemplate.requireFn}.nc);`),
|
2017-02-23 00:54:16 +08:00
|
|
|
"}",
|
2017-11-08 18:32:05 +08:00
|
|
|
`script.src = ${mainTemplate.requireFn}.p + ${scriptSrcPath};`,
|
2017-08-23 16:20:27 +08:00
|
|
|
"var timeout = setTimeout(function(){",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent([
|
2017-09-11 18:53:30 +08:00
|
|
|
"onScriptComplete({ type: 'timeout', target: script });",
|
2017-08-23 16:20:27 +08:00
|
|
|
]),
|
|
|
|
`}, ${chunkLoadTimeout});`,
|
2017-02-23 00:54:16 +08:00
|
|
|
"script.onerror = script.onload = onScriptComplete;",
|
2017-08-23 16:20:27 +08:00
|
|
|
"function onScriptComplete(event) {",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent([
|
2017-02-23 00:54:16 +08:00
|
|
|
"// avoid mem leaks in IE.",
|
|
|
|
"script.onerror = script.onload = null;",
|
|
|
|
"clearTimeout(timeout);",
|
|
|
|
"var chunk = installedChunks[chunkId];",
|
|
|
|
"if(chunk !== 0) {",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent([
|
2017-04-09 15:45:56 +08:00
|
|
|
"if(chunk) {",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent([
|
2017-09-11 18:53:30 +08:00
|
|
|
"var errorType = event && (event.type === 'load' ? 'missing' : event.type);",
|
|
|
|
"var realSrc = event && event.target && event.target.src;",
|
2017-08-23 16:20:27 +08:00
|
|
|
"var error = new Error('Loading chunk ' + chunkId + ' failed.\\n(' + errorType + ': ' + realSrc + ')');",
|
|
|
|
"error.type = errorType;",
|
|
|
|
"error.request = realSrc;",
|
|
|
|
"chunk[1](error);"
|
|
|
|
]),
|
2017-04-09 15:45:56 +08:00
|
|
|
"}",
|
2017-02-23 00:54:16 +08:00
|
|
|
"installedChunks[chunkId] = undefined;"
|
|
|
|
]),
|
|
|
|
"}"
|
2015-10-24 18:20:51 +08:00
|
|
|
]),
|
2017-02-23 00:54:16 +08:00
|
|
|
"};",
|
2014-06-03 03:23:53 +08:00
|
|
|
]);
|
2017-02-23 00:54:16 +08:00
|
|
|
});
|
2017-12-23 14:13:13 +08:00
|
|
|
mainTemplate.hooks.requireEnsure.tap("JsonpMainTemplatePlugin", (source, chunk, hash) => {
|
2017-12-07 16:42:33 +08:00
|
|
|
return Template.asString([
|
2017-10-30 20:56:57 +08:00
|
|
|
source,
|
2014-06-03 03:23:53 +08:00
|
|
|
"",
|
2017-10-30 20:56:57 +08:00
|
|
|
"// JSONP chunk loading for javascript",
|
2017-02-23 00:54:16 +08:00
|
|
|
"",
|
2017-10-30 20:56:57 +08:00
|
|
|
"var installedChunkData = installedChunks[chunkId];",
|
|
|
|
"if(installedChunkData !== 0) { // 0 means \"already installed\".",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent([
|
2017-10-30 20:56:57 +08:00
|
|
|
"",
|
|
|
|
"// a Promise means \"currently loading\".",
|
|
|
|
"if(installedChunkData) {",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent([
|
2017-10-30 20:56:57 +08:00
|
|
|
"promises.push(installedChunkData[2]);"
|
|
|
|
]),
|
|
|
|
"} else {",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent([
|
2017-10-30 20:56:57 +08:00
|
|
|
"// setup Promise in chunk cache",
|
|
|
|
"var promise = new Promise(function(resolve, reject) {",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent([
|
2017-10-30 20:56:57 +08:00
|
|
|
"installedChunkData = installedChunks[chunkId] = [resolve, reject];"
|
|
|
|
]),
|
|
|
|
"});",
|
2017-11-12 01:48:29 +08:00
|
|
|
"promises.push(installedChunkData[2] = promise);",
|
2017-10-30 20:56:57 +08:00
|
|
|
"",
|
|
|
|
"// start chunk loading",
|
|
|
|
"var head = document.getElementsByTagName('head')[0];",
|
2017-11-29 01:43:01 +08:00
|
|
|
mainTemplate.hooks.jsonpScript.call("", chunk, hash),
|
2017-11-12 01:48:29 +08:00
|
|
|
"head.appendChild(script);"
|
2017-10-30 20:56:57 +08:00
|
|
|
]),
|
|
|
|
"}",
|
2017-02-23 00:54:16 +08:00
|
|
|
]),
|
2017-10-30 20:56:57 +08:00
|
|
|
"}",
|
2017-02-23 00:54:16 +08:00
|
|
|
]);
|
|
|
|
});
|
2017-12-23 14:13:13 +08:00
|
|
|
mainTemplate.hooks.requireExtensions.tap("JsonpMainTemplatePlugin", (source, chunk) => {
|
2018-01-20 00:06:59 +08:00
|
|
|
if(!needChunkOnDemandLoadingCode(chunk)) return source;
|
2017-02-23 00:54:16 +08:00
|
|
|
|
2017-12-07 16:42:33 +08:00
|
|
|
return Template.asString([
|
2014-06-03 03:23:53 +08:00
|
|
|
source,
|
|
|
|
"",
|
2017-02-23 00:54:16 +08:00
|
|
|
"// on error function for async loading",
|
2017-11-08 18:32:05 +08:00
|
|
|
`${mainTemplate.requireFn}.oe = function(err) { console.error(err); throw err; };`
|
2017-02-23 00:54:16 +08:00
|
|
|
]);
|
|
|
|
});
|
2017-12-23 14:13:13 +08:00
|
|
|
mainTemplate.hooks.bootstrap.tap("JsonpMainTemplatePlugin", (source, chunk, hash) => {
|
2017-04-23 00:59:15 +08:00
|
|
|
if(needChunkLoadingCode(chunk)) {
|
2018-01-20 00:06:59 +08:00
|
|
|
const withDefer = needEntryDeferringCode(chunk);
|
2017-12-07 16:42:33 +08:00
|
|
|
return Template.asString([
|
2017-02-23 00:54:16 +08:00
|
|
|
source,
|
|
|
|
"",
|
|
|
|
"// install a JSONP callback for chunk loading",
|
2017-04-23 00:59:15 +08:00
|
|
|
"function webpackJsonpCallback(data) {",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent([
|
2018-01-20 00:06:59 +08:00
|
|
|
"var chunkIds = data[0];",
|
|
|
|
"var moreModules = data[1]",
|
|
|
|
withDefer ? "var executeModules = data[2];" : "",
|
2017-02-23 00:54:16 +08:00
|
|
|
"// add \"moreModules\" to the modules object,",
|
|
|
|
"// then flag all \"chunkIds\" as loaded and fire callback",
|
2018-01-20 00:06:59 +08:00
|
|
|
"var moduleId, chunkId, i = 0, resolves = [];",
|
2017-02-23 00:54:16 +08:00
|
|
|
"for(;i < chunkIds.length; i++) {",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent([
|
2017-02-23 00:54:16 +08:00
|
|
|
"chunkId = chunkIds[i];",
|
2017-04-09 15:45:56 +08:00
|
|
|
"if(installedChunks[chunkId]) {",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent("resolves.push(installedChunks[chunkId][0]);"),
|
2017-04-09 15:45:56 +08:00
|
|
|
"}",
|
2017-02-23 00:54:16 +08:00
|
|
|
"installedChunks[chunkId] = 0;"
|
|
|
|
]),
|
2017-03-31 21:16:55 +08:00
|
|
|
"}",
|
2017-02-23 00:54:16 +08:00
|
|
|
"for(moduleId in moreModules) {",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent([
|
2017-02-23 00:54:16 +08:00
|
|
|
"if(Object.prototype.hasOwnProperty.call(moreModules, moduleId)) {",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent(mainTemplate.renderAddModule(hash, chunk, "moduleId", "moreModules[moduleId]")),
|
2016-06-04 17:45:07 +08:00
|
|
|
"}"
|
2014-06-03 03:23:53 +08:00
|
|
|
]),
|
2016-06-06 02:35:42 +08:00
|
|
|
"}",
|
2017-04-23 00:59:15 +08:00
|
|
|
"if(parentJsonpFunction) parentJsonpFunction(data);",
|
2017-04-09 15:45:56 +08:00
|
|
|
"while(resolves.length) {",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent("resolves.shift()();"),
|
2017-04-09 15:45:56 +08:00
|
|
|
"}",
|
2018-01-20 00:06:59 +08:00
|
|
|
withDefer ? Template.asString([
|
2017-04-23 00:59:15 +08:00
|
|
|
"",
|
2018-01-20 00:06:59 +08:00
|
|
|
"// add entry modules from loaded chunk to deferred list",
|
|
|
|
"deferredModules.push.apply(deferredModules, executeModules || []);",
|
|
|
|
"",
|
|
|
|
"// run deferred modules when all chunks ready",
|
|
|
|
"return checkDeferredModules();"
|
|
|
|
]) : ""
|
|
|
|
]),
|
|
|
|
"};",
|
|
|
|
withDefer ? Template.asString([
|
|
|
|
"function checkDeferredModules() {",
|
|
|
|
Template.indent([
|
|
|
|
"var result;",
|
|
|
|
"for(var i = 0; i < deferredModules.length; i++) {",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent([
|
2018-01-20 00:06:59 +08:00
|
|
|
"var deferredModule = deferredModules[i];",
|
2017-04-23 00:59:15 +08:00
|
|
|
"var fullfilled = true;",
|
2018-01-20 00:06:59 +08:00
|
|
|
"for(var j = 1; j < deferredModule.length; j++) {",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent([
|
2018-01-20 00:06:59 +08:00
|
|
|
"var depId = deferredModule[j];",
|
2017-04-23 00:59:15 +08:00
|
|
|
"if(installedChunks[depId] !== 0) fullfilled = false;"
|
|
|
|
]),
|
|
|
|
"}",
|
|
|
|
"if(fullfilled) {",
|
2017-12-07 16:42:33 +08:00
|
|
|
Template.indent([
|
2018-01-20 00:06:59 +08:00
|
|
|
"deferredModules.splice(i--, 1);",
|
|
|
|
"result = " + mainTemplate.requireFn + "(" + mainTemplate.requireFn + ".s = deferredModule[0]);",
|
2017-04-23 00:59:15 +08:00
|
|
|
]),
|
2017-02-23 00:54:16 +08:00
|
|
|
"}"
|
|
|
|
]),
|
|
|
|
"}",
|
|
|
|
"return result;",
|
2018-01-20 00:06:59 +08:00
|
|
|
]),
|
|
|
|
"}"
|
|
|
|
]) : ""
|
2017-02-23 00:54:16 +08:00
|
|
|
]);
|
2014-08-22 19:51:24 +08:00
|
|
|
}
|
2017-02-23 00:54:16 +08:00
|
|
|
return source;
|
2014-08-22 19:51:24 +08:00
|
|
|
});
|
2018-01-20 00:06:59 +08:00
|
|
|
mainTemplate.hooks.beforeStartup.tap("JsonpMainTemplatePlugin", (source, chunk, hash) => {
|
2017-04-23 00:59:15 +08:00
|
|
|
if(needChunkLoadingCode(chunk)) {
|
2017-11-08 18:32:05 +08:00
|
|
|
var jsonpFunction = mainTemplate.outputOptions.jsonpFunction;
|
2017-12-28 01:46:37 +08:00
|
|
|
var globalObject = mainTemplate.outputOptions.globalObject;
|
2017-12-07 16:42:33 +08:00
|
|
|
return Template.asString([
|
2017-12-28 01:46:37 +08:00
|
|
|
`var jsonpArray = ${globalObject}[${JSON.stringify(jsonpFunction)}] = ${globalObject}[${JSON.stringify(jsonpFunction)}] || [];`,
|
2018-01-20 00:06:59 +08:00
|
|
|
"var oldJsonpFunction = jsonpArray.push.bind(jsonpArray);",
|
2017-04-23 00:59:15 +08:00
|
|
|
"jsonpArray.push = webpackJsonpCallback;",
|
|
|
|
"jsonpArray = jsonpArray.slice();",
|
|
|
|
"for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]);",
|
2018-01-20 00:06:59 +08:00
|
|
|
"var parentJsonpFunction = oldJsonpFunction;",
|
2017-04-23 00:59:15 +08:00
|
|
|
"",
|
|
|
|
source
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
return source;
|
|
|
|
});
|
2018-01-20 00:06:59 +08:00
|
|
|
mainTemplate.hooks.startup.tap("JsonpMainTemplatePlugin", (source, chunk, hash) => {
|
|
|
|
if(needEntryDeferringCode(chunk)) {
|
|
|
|
if(chunk.hasEntryModule()) {
|
|
|
|
const entries = [chunk.entryModule]
|
|
|
|
.filter(Boolean)
|
|
|
|
.map(m => [m.id].concat(Array.from(chunk.groupsIterable)[0].chunks.filter(c => c !== chunk).map(c => c.id)));
|
|
|
|
return Template.asString([
|
|
|
|
"// add entry module to deferred list",
|
|
|
|
`deferredModules.push(${entries.map(e => JSON.stringify(e)).join(", ")});`,
|
|
|
|
"// run deferred modules when ready",
|
|
|
|
"return checkDeferredModules();"
|
|
|
|
]);
|
|
|
|
} else {
|
|
|
|
return Template.asString([
|
|
|
|
"// run deferred modules from other chunks",
|
|
|
|
"checkDeferredModules();"
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return source;
|
|
|
|
});
|
2017-12-23 14:13:13 +08:00
|
|
|
mainTemplate.hooks.hotBootstrap.tap("JsonpMainTemplatePlugin", (source, chunk, hash) => {
|
2017-12-28 01:46:37 +08:00
|
|
|
const globalObject = mainTemplate.outputOptions.globalObject;
|
2017-11-08 18:32:05 +08:00
|
|
|
const hotUpdateChunkFilename = mainTemplate.outputOptions.hotUpdateChunkFilename;
|
|
|
|
const hotUpdateMainFilename = mainTemplate.outputOptions.hotUpdateMainFilename;
|
|
|
|
const crossOriginLoading = mainTemplate.outputOptions.crossOriginLoading;
|
|
|
|
const hotUpdateFunction = mainTemplate.outputOptions.hotUpdateFunction;
|
2017-11-29 01:43:01 +08:00
|
|
|
const currentHotUpdateChunkFilename = mainTemplate.getAssetPath(JSON.stringify(hotUpdateChunkFilename), {
|
2017-11-08 18:32:05 +08:00
|
|
|
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
|
|
|
|
hashWithLength: length => `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`,
|
2017-02-23 00:54:16 +08:00
|
|
|
chunk: {
|
|
|
|
id: "\" + chunkId + \""
|
|
|
|
}
|
|
|
|
});
|
2017-11-29 01:43:01 +08:00
|
|
|
const currentHotUpdateMainFilename = mainTemplate.getAssetPath(JSON.stringify(hotUpdateMainFilename), {
|
2017-11-08 18:32:05 +08:00
|
|
|
hash: `" + ${mainTemplate.renderCurrentHashCode(hash)} + "`,
|
|
|
|
hashWithLength: length => `" + ${mainTemplate.renderCurrentHashCode(hash, length)} + "`
|
2017-02-23 00:54:16 +08:00
|
|
|
});
|
2017-02-28 22:25:31 +08:00
|
|
|
const runtimeSource = Template.getFunctionContent(require("./JsonpMainTemplate.runtime.js"))
|
2017-02-23 00:54:16 +08:00
|
|
|
.replace(/\/\/\$semicolon/g, ";")
|
2017-11-08 18:32:05 +08:00
|
|
|
.replace(/\$require\$/g, mainTemplate.requireFn)
|
2017-09-28 03:16:34 +08:00
|
|
|
.replace(/\$crossOriginLoading\$/g, crossOriginLoading ? `script.crossOrigin = ${JSON.stringify(crossOriginLoading)}` : "")
|
2017-02-23 00:54:16 +08:00
|
|
|
.replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename)
|
|
|
|
.replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename)
|
|
|
|
.replace(/\$hash\$/g, JSON.stringify(hash));
|
|
|
|
return `${source}
|
|
|
|
function hotDisposeChunk(chunkId) {
|
|
|
|
delete installedChunks[chunkId];
|
|
|
|
}
|
2017-12-28 01:46:37 +08:00
|
|
|
var parentHotUpdateCallback = ${globalObject}[${JSON.stringify(hotUpdateFunction)}];
|
|
|
|
${globalObject}[${JSON.stringify(hotUpdateFunction)}] = ${runtimeSource}`;
|
2014-08-22 19:51:24 +08:00
|
|
|
});
|
2017-12-23 14:13:13 +08:00
|
|
|
mainTemplate.hooks.hash.tap("JsonpMainTemplatePlugin", hash => {
|
2017-02-23 00:54:16 +08:00
|
|
|
hash.update("jsonp");
|
2017-04-23 00:59:15 +08:00
|
|
|
hash.update("5");
|
2017-12-28 01:46:37 +08:00
|
|
|
hash.update(`${mainTemplate.outputOptions.globalObject}`);
|
2017-11-08 18:32:05 +08:00
|
|
|
hash.update(`${mainTemplate.outputOptions.chunkFilename}`);
|
|
|
|
hash.update(`${mainTemplate.outputOptions.jsonpFunction}`);
|
|
|
|
hash.update(`${mainTemplate.outputOptions.hotUpdateFunction}`);
|
2017-02-23 00:54:16 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports = JsonpMainTemplatePlugin;
|