【发布时间】:2023-03-07 21:57:01
【问题描述】:
我是一名 HTML/CSS/PHP/MYSQL 程序员,现在正在尝试学习一些 javascript。我正在通过挖掘我目前正在使用的网络邮件的代码(开源)并试图了解它是如何工作的来做到这一点的。我试图了解页面的不同部分是如何加载的(没有在 PHP 中重新加载的页面)。如果我没记错的话,那就是使用 webpack 来做到这一点。如果我没记错的话,页面的每个部分都作为模块加载。
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "webmail/v/0.0.0/static/js/";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
这似乎是(部分)使这种魔法成为可能的代码。现在,稍后在代码中 webpack 是这样使用的:
AbstractSystemDropDownUserView.prototype.settingsClick = function ()
{
__webpack_require__(/*! Knoin/Knoin */ 5).setHash(Links.settings());
};
如果我是正确的,这个函数会在点击按钮时加载一个模块,就像 settingsClick 一样。但是,模块编号在哪里定义/分配?
非常感谢任何帮助我上路的人!
【问题讨论】:
标签: javascript module webpack