remove customizability of __webpack_require__ function name

This commit is contained in:
Tobias Koppers 2018-11-05 13:13:05 +01:00
parent cf76e1c0e2
commit 4f813e28a9
13 changed files with 62 additions and 77 deletions

2
declarations.d.ts vendored
View File

@ -237,7 +237,7 @@ interface RuleSetConditionsAbsoluteRecursive
declare const $hash$;
declare const $requestTimeout$;
declare const installedModules;
declare const $require$;
declare const __webpack_require__;
declare const hotDownloadManifest;
declare const hotDownloadUpdateChunk;
declare const hotDisposeChunk;

View File

@ -50,12 +50,10 @@ class ExtendedAPIPlugin {
const buf = [source];
buf.push("");
buf.push("// __webpack_hash__");
buf.push(`${mainTemplate.requireFn}.h = ${JSON.stringify(hash)};`);
buf.push(`__webpack_require__.h = ${JSON.stringify(hash)};`);
buf.push("");
buf.push("// __webpack_chunkname__");
buf.push(
`${mainTemplate.requireFn}.cn = ${JSON.stringify(chunk.name)};`
);
buf.push(`__webpack_require__.cn = ${JSON.stringify(chunk.name)};`);
return Template.asString(buf);
}
);

View File

@ -5,7 +5,7 @@
"use strict";
/*global $hash$ $requestTimeout$ installedModules $require$ hotDownloadManifest hotDownloadUpdateChunk hotDisposeChunk modules */
/*global $hash$ $requestTimeout$ installedModules __webpack_require__ hotDownloadManifest hotDownloadUpdateChunk hotDisposeChunk modules */
module.exports = function() {
var hotApplyOnUpdate = true;
@ -22,7 +22,7 @@ module.exports = function() {
// eslint-disable-next-line no-unused-vars
function hotCreateRequire(moduleId) {
var me = installedModules[moduleId];
if (!me) return $require$;
if (!me) return __webpack_require__;
var fn = function(request) {
if (me.hot.active) {
if (installedModules[request]) {
@ -45,23 +45,23 @@ module.exports = function() {
);
hotCurrentParents = [];
}
return $require$(request);
return __webpack_require__(request);
};
var ObjectFactory = function ObjectFactory(name) {
return {
configurable: true,
enumerable: true,
get: function() {
return $require$[name];
return __webpack_require__[name];
},
set: function(value) {
$require$[name] = value;
__webpack_require__[name] = value;
}
};
};
for (var name in $require$) {
for (var name in __webpack_require__) {
if (
Object.prototype.hasOwnProperty.call($require$, name) &&
Object.prototype.hasOwnProperty.call(__webpack_require__, name) &&
name !== "e" &&
name !== "t"
) {
@ -71,10 +71,12 @@ module.exports = function() {
fn.e = function(chunkId) {
if (hotStatus === "ready") hotSetStatus("prepare");
hotChunksLoading++;
return $require$.e(chunkId).then(finishChunkLoading, function(err) {
finishChunkLoading();
throw err;
});
return __webpack_require__
.e(chunkId)
.then(finishChunkLoading, function(err) {
finishChunkLoading();
throw err;
});
function finishChunkLoading() {
hotChunksLoading--;
@ -90,7 +92,7 @@ module.exports = function() {
};
fn.t = function(value, mode) {
if (mode & 1) value = fn(value);
return $require$.t(value, mode & ~1);
return __webpack_require__.t(value, mode & ~1);
};
return fn;
}
@ -601,7 +603,7 @@ module.exports = function() {
moduleId = item.module;
hotCurrentParents = [moduleId];
try {
$require$(moduleId);
__webpack_require__(moduleId);
} catch (err) {
if (typeof item.errorHandler === "function") {
try {

View File

@ -389,8 +389,7 @@ class HotModuleReplacementPlugin {
buf.push("");
buf.push("// __webpack_hash__");
buf.push(
mainTemplate.requireFn +
".h = function() { return hotCurrentHash; };"
"__webpack_require__.h = function() { return hotCurrentHash; };"
);
return Template.asString(buf);
}
@ -412,7 +411,6 @@ class HotModuleReplacementPlugin {
hotSource,
"",
hotInitCode
.replace(/\$require\$/g, mainTemplate.requireFn)
.replace(/\$hash\$/g, JSON.stringify(hash))
.replace(/\$requestTimeout\$/g, requestTimeout)
.replace(

View File

@ -160,7 +160,7 @@ module.exports = class MainTemplate {
hash,
chunk,
JSON.stringify(moduleId)
)}(${this.requireFn}.s = ${JSON.stringify(moduleId)});`
)}(__webpack_require__.s = ${JSON.stringify(moduleId)});`
);
}
}
@ -261,7 +261,7 @@ module.exports = class MainTemplate {
if (Object.keys(chunkMaps.hash).length) {
buf.push("// This file contains only the entry chunk.");
buf.push("// The chunk loading function for additional chunks");
buf.push(`${this.requireFn}.e = function requireEnsure(chunkId) {`);
buf.push(`__webpack_require__.e = function requireEnsure(chunkId) {`);
buf.push(Template.indent("var promises = [];"));
buf.push(
Template.indent(
@ -283,24 +283,24 @@ module.exports = class MainTemplate {
buf.push("// The chunk loading function for additional chunks");
buf.push("// Since all referenced chunks are already included");
buf.push("// in this file, this function is empty here.");
buf.push(`${this.requireFn}.e = function requireEnsure() {`);
buf.push(`__webpack_require__.e = function requireEnsure() {`);
buf.push(Template.indent("return Promise.resolve();"));
buf.push("};");
}
buf.push("");
buf.push("// expose the modules object (__webpack_modules__)");
buf.push(`${this.requireFn}.m = modules;`);
buf.push(`__webpack_require__.m = modules;`);
buf.push("");
buf.push("// expose the module cache");
buf.push(`${this.requireFn}.c = installedModules;`);
buf.push(`__webpack_require__.c = installedModules;`);
buf.push("");
buf.push("// define getter function for harmony exports");
buf.push(`${this.requireFn}.d = function(exports, name, getter) {`);
buf.push(`__webpack_require__.d = function(exports, name, getter) {`);
buf.push(
Template.indent([
`if(!${this.requireFn}.o(exports, name)) {`,
`if(!__webpack_require__.o(exports, name)) {`,
Template.indent([
"Object.defineProperty(exports, name, { enumerable: true, get: getter });"
]),
@ -311,7 +311,7 @@ module.exports = class MainTemplate {
buf.push("");
buf.push("// define __esModule on exports");
buf.push(`${this.requireFn}.r = function(exports) {`);
buf.push(`__webpack_require__.r = function(exports) {`);
buf.push(
Template.indent([
"if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {",
@ -330,17 +330,17 @@ module.exports = class MainTemplate {
buf.push("// mode & 2: merge all properties of value into the ns");
buf.push("// mode & 4: return value when already ns object");
buf.push("// mode & 8|1: behave like require");
buf.push(`${this.requireFn}.t = function(value, mode) {`);
buf.push(`__webpack_require__.t = function(value, mode) {`);
buf.push(
Template.indent([
`if(mode & 1) value = ${this.requireFn}(value);`,
`if(mode & 1) value = __webpack_require__(value);`,
`if(mode & 8) return value;`,
"if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;",
"var ns = Object.create(null);",
`${this.requireFn}.r(ns);`,
`__webpack_require__.r(ns);`,
"Object.defineProperty(ns, 'default', { enumerable: true, value: value });",
"if(mode & 2 && typeof value != 'string') for(var key in value) " +
`${this.requireFn}.d(ns, key, function(key) { ` +
`__webpack_require__.d(ns, key, function(key) { ` +
"return value[key]; " +
"}.bind(null, key));",
"return ns;"
@ -352,7 +352,7 @@ module.exports = class MainTemplate {
buf.push(
"// getDefaultExport function for compatibility with non-harmony modules"
);
buf.push(this.requireFn + ".n = function(module) {");
buf.push("__webpack_require__.n = function(module) {");
buf.push(
Template.indent([
"var getter = module && module.__esModule ?",
@ -360,7 +360,7 @@ module.exports = class MainTemplate {
"function getDefault() { return module['default']; } :",
"function getModuleExports() { return module; };"
]),
`${this.requireFn}.d(getter, 'a', getter);`,
`__webpack_require__.d(getter, 'a', getter);`,
"return getter;"
])
);
@ -369,9 +369,7 @@ module.exports = class MainTemplate {
buf.push("");
buf.push("// Object.prototype.hasOwnProperty.call");
buf.push(
`${
this.requireFn
}.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };`
`__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };`
);
const publicPath = this.getPublicPath({
@ -379,12 +377,14 @@ module.exports = class MainTemplate {
});
buf.push("");
buf.push("// __webpack_public_path__");
buf.push(`${this.requireFn}.p = ${JSON.stringify(publicPath)};`);
buf.push(`__webpack_require__.p = ${JSON.stringify(publicPath)};`);
return Template.asString(buf);
}
);
}
this.requireFn = "__webpack_require__";
get requireFn() {
return "__webpack_require__";
}
/**
@ -411,7 +411,7 @@ module.exports = class MainTemplate {
buf.push(this.hooks.localVars.call("", chunk, hash));
buf.push("");
buf.push("// The require function");
buf.push(`function ${this.requireFn}(moduleId) {`);
buf.push(`function __webpack_require__(moduleId) {`);
buf.push(Template.indent(this.hooks.require.call("", renderContext)));
buf.push("}");
buf.push("");
@ -461,7 +461,7 @@ module.exports = class MainTemplate {
*/
renderRequireFunctionForModule(hash, chunk, varModuleId) {
return this.hooks.moduleRequire.call(
this.requireFn,
"__webpack_require__",
chunk,
hash,
varModuleId

View File

@ -5,7 +5,7 @@
"use strict";
/*global installedChunks $hotChunkFilename$ $require$ hotAddUpdateChunk $hotMainFilename$ */
/*global installedChunks $hotChunkFilename$ __webpack_require__ hotAddUpdateChunk $hotMainFilename$ */
module.exports = function() {
// eslint-disable-next-line no-unused-vars
@ -13,7 +13,7 @@ module.exports = function() {
var filename = require("path").join(__dirname, $hotChunkFilename$);
require("fs").readFile(filename, "utf-8", function(err, content) {
if (err) {
if ($require$.onError) return $require$.oe(err);
if (__webpack_require__.onError) return __webpack_require__.oe(err);
throw err;
}
var chunk = {};

View File

@ -54,7 +54,7 @@ module.exports = class NodeMainTemplatePlugin {
source,
"",
"// uncaught error handler for webpack runtime",
`${mainTemplate.requireFn}.oe = function(err) {`,
`__webpack_require__.oe = function(err) {`,
Template.indent([
"process.nextTick(function() {",
Template.indent(
@ -320,7 +320,6 @@ module.exports = class NodeMainTemplatePlugin {
? require("./NodeMainTemplateAsync.runtime")
: require("./NodeMainTemplate.runtime")
)
.replace(/\$require\$/g, mainTemplate.requireFn)
.replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename)
.replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename);
});

View File

@ -336,9 +336,7 @@ class WasmMainTemplatePlugin {
"}",
"promises.push(installedWasmModules[wasmModuleId] = promise.then(function(res) {",
Template.indent([
`return ${
mainTemplate.requireFn
}.w[wasmModuleId] = (res.instance || res).exports;`
`return __webpack_require__.w[wasmModuleId] = (res.instance || res).exports;`
]),
"}));"
]),
@ -363,7 +361,7 @@ class WasmMainTemplatePlugin {
source,
"",
"// object with all WebAssembly.instance exports",
`${mainTemplate.requireFn}.w = {};`
`__webpack_require__.w = {};`
]);
}
);

View File

@ -18,7 +18,7 @@ class FetchCompileWasmTemplatePlugin {
compilation => {
const mainTemplate = compilation.mainTemplate;
const generateLoadBinaryCode = path =>
`fetch(${mainTemplate.requireFn}.p + ${path})`;
`fetch(__webpack_require__.p + ${path})`;
const plugin = new WasmMainTemplatePlugin(
compilation,

View File

@ -5,7 +5,7 @@
"use strict";
/*globals hotAddUpdateChunk parentHotUpdateCallback document XMLHttpRequest $require$ $hotChunkFilename$ $hotMainFilename$ $crossOriginLoading$ */
/*globals hotAddUpdateChunk parentHotUpdateCallback document XMLHttpRequest __webpack_require__ $hotChunkFilename$ $hotMainFilename$ $crossOriginLoading$ */
module.exports = function() {
// eslint-disable-next-line no-unused-vars
@ -19,7 +19,7 @@ module.exports = function() {
var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.charset = "utf-8";
script.src = $require$.p + $hotChunkFilename$;
script.src = __webpack_require__.p + $hotChunkFilename$;
if ($crossOriginLoading$) script.crossOrigin = $crossOriginLoading$;
head.appendChild(script);
}
@ -33,7 +33,7 @@ module.exports = function() {
}
try {
var request = new XMLHttpRequest();
var requestPath = $require$.p + $hotMainFilename$;
var requestPath = __webpack_require__.p + $hotMainFilename$;
request.open("GET", requestPath, true);
request.timeout = requestTimeout;
request.send(null);

View File

@ -154,7 +154,7 @@ class JsonpMainTemplatePlugin {
"// script path function",
"function jsonpScriptSrc(chunkId) {",
Template.indent([
`return ${mainTemplate.requireFn}.p + ${getScriptSrcPath(
`return __webpack_require__.p + ${getScriptSrcPath(
hash,
chunk,
"chunkId"
@ -191,9 +191,9 @@ class JsonpMainTemplatePlugin {
: "",
"script.charset = 'utf-8';",
`script.timeout = ${chunkLoadTimeout / 1000};`,
`if (${mainTemplate.requireFn}.nc) {`,
`if (__webpack_require__.nc) {`,
Template.indent(
`script.setAttribute("nonce", ${mainTemplate.requireFn}.nc);`
`script.setAttribute("nonce", __webpack_require__.nc);`
),
"}",
"script.src = jsonpScriptSrc(chunkId);",
@ -247,10 +247,8 @@ class JsonpMainTemplatePlugin {
? `link.type = ${JSON.stringify(jsonpScriptType)};`
: "",
"link.charset = 'utf-8';",
`if (${mainTemplate.requireFn}.nc) {`,
Template.indent(
`link.setAttribute("nonce", ${mainTemplate.requireFn}.nc);`
),
`if (__webpack_require__.nc) {`,
Template.indent(`link.setAttribute("nonce", __webpack_require__.nc);`),
"}",
'link.rel = "preload";',
'link.as = "script";',
@ -274,10 +272,8 @@ class JsonpMainTemplatePlugin {
crossOriginLoading
? `link.crossOrigin = ${JSON.stringify(crossOriginLoading)};`
: "",
`if (${mainTemplate.requireFn}.nc) {`,
Template.indent(
`link.setAttribute("nonce", ${mainTemplate.requireFn}.nc);`
),
`if (__webpack_require__.nc) {`,
Template.indent(`link.setAttribute("nonce", __webpack_require__.nc);`),
"}",
'link.rel = "prefetch";',
'link.as = "script";',
@ -367,9 +363,7 @@ class JsonpMainTemplatePlugin {
source,
"",
"// on error function for async loading",
`${
mainTemplate.requireFn
}.oe = function(err) { console.error(err); throw err; };`
`__webpack_require__.oe = function(err) { console.error(err); throw err; };`
]);
}
);
@ -467,10 +461,8 @@ class JsonpMainTemplatePlugin {
Template.indent([
"deferredModules.splice(i--, 1);",
"result = " +
mainTemplate.requireFn +
"(" +
mainTemplate.requireFn +
".s = deferredModule[0]);"
"__webpack_require__(" +
"__webpack_require__.s = deferredModule[0]);"
]),
"}"
]),
@ -582,7 +574,6 @@ class JsonpMainTemplatePlugin {
require("./JsonpMainTemplate.runtime")
)
.replace(/\/\/\$semicolon/g, ";")
.replace(/\$require\$/g, mainTemplate.requireFn)
.replace(
/\$crossOriginLoading\$/g,
crossOriginLoading ? JSON.stringify(crossOriginLoading) : "null"

View File

@ -5,7 +5,7 @@
"use strict";
/*globals installedChunks hotAddUpdateChunk parentHotUpdateCallback importScripts XMLHttpRequest $require$ $hotChunkFilename$ $hotMainFilename$ */
/*globals installedChunks hotAddUpdateChunk parentHotUpdateCallback importScripts XMLHttpRequest __webpack_require__ $hotChunkFilename$ $hotMainFilename$ */
module.exports = function() {
// eslint-disable-next-line no-unused-vars
@ -16,7 +16,7 @@ module.exports = function() {
// eslint-disable-next-line no-unused-vars
function hotDownloadUpdateChunk(chunkId) {
importScripts($require$.p + $hotChunkFilename$);
importScripts(__webpack_require__.p + $hotChunkFilename$);
}
// eslint-disable-next-line no-unused-vars
@ -28,7 +28,7 @@ module.exports = function() {
}
try {
var request = new XMLHttpRequest();
var requestPath = $require$.p + $hotMainFilename$;
var requestPath = __webpack_require__.p + $hotMainFilename$;
request.open("GET", requestPath, true);
request.timeout = requestTimeout;
request.send(null);

View File

@ -183,7 +183,6 @@ class WebWorkerMainTemplatePlugin {
`${globalObject}[${JSON.stringify(hotUpdateFunction)}] = ` +
Template.getFunctionContent(require("./WebWorkerMainTemplate.runtime"))
.replace(/\/\/\$semicolon/g, ";")
.replace(/\$require\$/g, mainTemplate.requireFn)
.replace(/\$hotMainFilename\$/g, currentHotUpdateMainFilename)
.replace(/\$hotChunkFilename\$/g, currentHotUpdateChunkFilename)
.replace(/\$hash\$/g, JSON.stringify(hash))