Skip to content

Chunk loader function with complex logic won't be run #2

Description

@e4ac

If a chunk loader contains complex logic it will not be run. For example:

function loader(chunkId) {
  return __webpack_require__.p + "" + ({ "1": "chunk1", "2": "chunk2" }[chunkId] || chunkId) + ".js";
}

Looks simple enough. However, This __webpack_require__.p is generated by:

var scriptUrl;
if (__webpack_require__.g.importScripts) scriptUrl = __webpack_require__.g.location + "";
var document = __webpack_require__.g.document;
if (!scriptUrl && document) {
  if (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT')
    scriptUrl = document.currentScript.src;
  if (!scriptUrl) {
    var scripts = document.getElementsByTagName("script");
    if(scripts.length) {
      var i = scripts.length - 1;
      while (i > -1 && (!scriptUrl || !/^http(s?):/.test(scriptUrl))) scriptUrl = scripts[i--].src;
    }
  }
}
if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser");
scriptUrl = scriptUrl.replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/");
__webpack_require__.p = scriptUrl;

Which is pretty complex, involving lots of other members.

Currently, the algorithm can only handle simple hardcoded values, such as __webpack_require__.p = "value" and cannot perform more complex logic like the example above.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions