文章目录

学习 webpack 打包

1
2
3
4
5
6
7
8
yarn init

yarn add webpack webpack-cli

mkdir src

touch index.js

1
npx webpack --mode=development  src/index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
(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] = {
i: moduleId,
l: false,
exports: {}
};

// Execute the module function
modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);

// Flag the module as loaded
module.l = true;

// Return the exports of the module
return module.exports;
}


// Load entry module and return exports
return __webpack_require__(__webpack_require__.s = "./src/index.js");
})
({

"./src/index.js":
(function (module, exports) {

eval("const a = \"hello world\";\nconsole.log(a);\n\n\n//# sourceURL=webpack:///./src/index.js?");

})

});

回顾

  • 立即执行函数
  • call
  • 模块
文章目录
Fork me on GitHub