2021-06-23 19:58:40 +08:00
|
|
|
# example.js
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
import { resetCounter, print } from "./methods";
|
|
|
|
|
|
|
|
setTimeout(async () => {
|
|
|
|
const counter = await import("./counter");
|
|
|
|
print(counter.value);
|
|
|
|
counter.increment();
|
|
|
|
counter.increment();
|
|
|
|
counter.increment();
|
|
|
|
print(counter.value);
|
|
|
|
await resetCounter();
|
|
|
|
print(counter.value);
|
|
|
|
}, 100);
|
|
|
|
```
|
|
|
|
|
|
|
|
# methods.js
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
export const resetCounter = async () => {
|
|
|
|
(await import("./counter")).reset();
|
|
|
|
};
|
|
|
|
|
|
|
|
export const print = value => console.log(value);
|
|
|
|
```
|
|
|
|
|
|
|
|
# counter.js
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
export let value = 0;
|
|
|
|
export function increment() {
|
|
|
|
value++;
|
|
|
|
}
|
|
|
|
export function decrement() {
|
|
|
|
value--;
|
|
|
|
}
|
|
|
|
export function reset() {
|
|
|
|
value = 0;
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
# dist/output.js
|
|
|
|
|
|
|
|
```javascript
|
|
|
|
/******/ var __webpack_modules__ = ({});
|
|
|
|
```
|
|
|
|
|
|
|
|
<details><summary><code>/* webpack runtime code */</code></summary>
|
|
|
|
|
|
|
|
``` js
|
|
|
|
/************************************************************************/
|
|
|
|
/******/ // The module cache
|
|
|
|
/******/ var __webpack_module_cache__ = {};
|
|
|
|
/******/
|
|
|
|
/******/ // The require function
|
|
|
|
/******/ function __webpack_require__(moduleId) {
|
|
|
|
/******/ // Check if module is in cache
|
|
|
|
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
|
|
|
/******/ if (cachedModule !== undefined) {
|
|
|
|
/******/ return cachedModule.exports;
|
|
|
|
/******/ }
|
|
|
|
/******/ // Create a new module (and put it into the cache)
|
|
|
|
/******/ var module = __webpack_module_cache__[moduleId] = {
|
|
|
|
/******/ // no module.id needed
|
|
|
|
/******/ // no module.loaded needed
|
|
|
|
/******/ exports: {}
|
|
|
|
/******/ };
|
|
|
|
/******/
|
|
|
|
/******/ // Execute the module function
|
|
|
|
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
|
|
|
|
/******/
|
|
|
|
/******/ // Return the exports of the module
|
|
|
|
/******/ return module.exports;
|
|
|
|
/******/ }
|
|
|
|
/******/
|
|
|
|
/******/ // expose the modules object (__webpack_modules__)
|
|
|
|
/******/ __webpack_require__.m = __webpack_modules__;
|
|
|
|
/******/
|
|
|
|
/************************************************************************/
|
|
|
|
/******/ /* webpack/runtime/define property getters */
|
|
|
|
/******/ (() => {
|
|
|
|
/******/ // define getter functions for harmony exports
|
|
|
|
/******/ __webpack_require__.d = (exports, definition) => {
|
|
|
|
/******/ for(var key in definition) {
|
|
|
|
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
|
|
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
|
|
/******/ }
|
|
|
|
/******/ }
|
|
|
|
/******/ };
|
|
|
|
/******/ })();
|
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/ensure chunk */
|
|
|
|
/******/ (() => {
|
|
|
|
/******/ __webpack_require__.f = {};
|
|
|
|
/******/ // This file contains only the entry chunk.
|
|
|
|
/******/ // The chunk loading function for additional chunks
|
|
|
|
/******/ __webpack_require__.e = (chunkId) => {
|
|
|
|
/******/ return Promise.all(Object.keys(__webpack_require__.f).reduce((promises, key) => {
|
|
|
|
/******/ __webpack_require__.f[key](chunkId, promises);
|
|
|
|
/******/ return promises;
|
|
|
|
/******/ }, []));
|
|
|
|
/******/ };
|
|
|
|
/******/ })();
|
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/get javascript chunk filename */
|
|
|
|
/******/ (() => {
|
|
|
|
/******/ // This function allow to reference async chunks
|
|
|
|
/******/ __webpack_require__.u = (chunkId) => {
|
|
|
|
/******/ // return url for filenames based on template
|
|
|
|
/******/ return "" + chunkId + ".output.js";
|
|
|
|
/******/ };
|
|
|
|
/******/ })();
|
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
|
|
|
/******/ (() => {
|
|
|
|
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
|
|
/******/ })();
|
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/make namespace object */
|
|
|
|
/******/ (() => {
|
|
|
|
/******/ // define __esModule on exports
|
|
|
|
/******/ __webpack_require__.r = (exports) => {
|
|
|
|
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
|
|
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
|
/******/ }
|
|
|
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
|
/******/ };
|
|
|
|
/******/ })();
|
|
|
|
/******/
|
2025-04-25 01:57:25 +08:00
|
|
|
/******/ /* webpack/runtime/publicPath */
|
|
|
|
/******/ (() => {
|
|
|
|
/******/ __webpack_require__.p = "dist/";
|
|
|
|
/******/ })();
|
|
|
|
/******/
|
2021-06-23 19:58:40 +08:00
|
|
|
/******/ /* webpack/runtime/import chunk loading */
|
|
|
|
/******/ (() => {
|
|
|
|
/******/ // no baseURI
|
|
|
|
/******/
|
|
|
|
/******/ // object to store loaded and loading chunks
|
|
|
|
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
|
2025-04-25 01:57:25 +08:00
|
|
|
/******/ // [resolve, Promise] = chunk loading, 0 = chunk loaded
|
2021-06-23 19:58:40 +08:00
|
|
|
/******/ var installedChunks = {
|
|
|
|
/******/ 0: 0
|
|
|
|
/******/ };
|
|
|
|
/******/
|
2021-08-20 14:12:50 +08:00
|
|
|
/******/ var installChunk = (data) => {
|
2025-04-25 01:57:25 +08:00
|
|
|
/******/ var {__webpack_ids__, __webpack_modules__, __webpack_runtime__} = data;
|
2021-08-20 14:12:50 +08:00
|
|
|
/******/ // add "modules" to the modules object,
|
|
|
|
/******/ // then flag all "ids" as loaded and fire callback
|
|
|
|
/******/ var moduleId, chunkId, i = 0;
|
2025-04-25 01:57:25 +08:00
|
|
|
/******/ for(moduleId in __webpack_modules__) {
|
|
|
|
/******/ if(__webpack_require__.o(__webpack_modules__, moduleId)) {
|
|
|
|
/******/ __webpack_require__.m[moduleId] = __webpack_modules__[moduleId];
|
2021-08-20 14:12:50 +08:00
|
|
|
/******/ }
|
|
|
|
/******/ }
|
2025-04-25 01:57:25 +08:00
|
|
|
/******/ if(__webpack_runtime__) __webpack_runtime__(__webpack_require__);
|
|
|
|
/******/ for(;i < __webpack_ids__.length; i++) {
|
|
|
|
/******/ chunkId = __webpack_ids__[i];
|
2021-08-20 14:12:50 +08:00
|
|
|
/******/ if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {
|
|
|
|
/******/ installedChunks[chunkId][0]();
|
|
|
|
/******/ }
|
2025-04-25 01:57:25 +08:00
|
|
|
/******/ installedChunks[__webpack_ids__[i]] = 0;
|
2021-08-20 14:12:50 +08:00
|
|
|
/******/ }
|
|
|
|
/******/
|
|
|
|
/******/ }
|
|
|
|
/******/
|
2021-06-23 19:58:40 +08:00
|
|
|
/******/ __webpack_require__.f.j = (chunkId, promises) => {
|
2021-06-28 18:30:25 +08:00
|
|
|
/******/ // import() chunk loading for javascript
|
2021-06-23 19:58:40 +08:00
|
|
|
/******/ var installedChunkData = __webpack_require__.o(installedChunks, chunkId) ? installedChunks[chunkId] : undefined;
|
|
|
|
/******/ if(installedChunkData !== 0) { // 0 means "already installed".
|
|
|
|
/******/
|
|
|
|
/******/ // a Promise means "currently loading".
|
|
|
|
/******/ if(installedChunkData) {
|
|
|
|
/******/ promises.push(installedChunkData[1]);
|
|
|
|
/******/ } else {
|
|
|
|
/******/ if(true) { // all chunks have JS
|
|
|
|
/******/ // setup Promise in chunk cache
|
2025-05-28 22:41:15 +08:00
|
|
|
/******/ var promise = import(__webpack_require__.p + __webpack_require__.u(chunkId)).then(installChunk, (e) => {
|
2021-06-23 19:58:40 +08:00
|
|
|
/******/ if(installedChunks[chunkId] !== 0) installedChunks[chunkId] = undefined;
|
|
|
|
/******/ throw e;
|
|
|
|
/******/ });
|
|
|
|
/******/ var promise = Promise.race([promise, new Promise((resolve) => (installedChunkData = installedChunks[chunkId] = [resolve]))])
|
|
|
|
/******/ promises.push(installedChunkData[1] = promise);
|
2025-04-25 01:57:25 +08:00
|
|
|
/******/ }
|
2021-06-23 19:58:40 +08:00
|
|
|
/******/ }
|
|
|
|
/******/ }
|
|
|
|
/******/ };
|
|
|
|
/******/
|
2025-04-25 01:57:25 +08:00
|
|
|
/******/ // no prefetching
|
|
|
|
/******/
|
|
|
|
/******/ // no preloaded
|
|
|
|
/******/
|
2021-08-20 14:12:50 +08:00
|
|
|
/******/ // no external install chunk
|
|
|
|
/******/
|
2021-06-23 19:58:40 +08:00
|
|
|
/******/ // no on chunks loaded
|
|
|
|
/******/ })();
|
|
|
|
/******/
|
|
|
|
/************************************************************************/
|
|
|
|
```
|
|
|
|
|
|
|
|
</details>
|
|
|
|
|
|
|
|
``` js
|
|
|
|
var __webpack_exports__ = {};
|
|
|
|
/*!********************************!*\
|
|
|
|
!*** ./example.js + 1 modules ***!
|
|
|
|
\********************************/
|
|
|
|
/*! namespace exports */
|
|
|
|
/*! runtime requirements: __webpack_require__.e, __webpack_require__, __webpack_require__.* */
|
|
|
|
|
2025-04-25 01:57:25 +08:00
|
|
|
;// ./methods.js
|
2021-06-23 19:58:40 +08:00
|
|
|
const resetCounter = async () => {
|
|
|
|
(await __webpack_require__.e(/*! import() */ 1).then(__webpack_require__.bind(__webpack_require__, /*! ./counter */ 1))).reset();
|
|
|
|
};
|
|
|
|
|
|
|
|
const print = value => console.log(value);
|
|
|
|
|
2025-04-25 01:57:25 +08:00
|
|
|
;// ./example.js
|
2021-06-23 19:58:40 +08:00
|
|
|
|
|
|
|
|
|
|
|
setTimeout(async () => {
|
|
|
|
const counter = await __webpack_require__.e(/*! import() */ 1).then(__webpack_require__.bind(__webpack_require__, /*! ./counter */ 1));
|
|
|
|
print(counter.value);
|
|
|
|
counter.increment();
|
|
|
|
counter.increment();
|
|
|
|
counter.increment();
|
|
|
|
print(counter.value);
|
|
|
|
await resetCounter();
|
|
|
|
print(counter.value);
|
|
|
|
}, 100);
|
|
|
|
```
|
|
|
|
|
|
|
|
# dist/output.js (production)
|
|
|
|
|
|
|
|
```javascript
|
2025-05-28 22:41:15 +08:00
|
|
|
var e,t,o={},r={};function n(e){var t=r[e];if(void 0!==t)return t.exports;var i=r[e]={exports:{}};return o[e](i,i.exports,n),i.exports}n.m=o,n.d=(e,t)=>{for(var o in t)n.o(t,o)&&!n.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},n.f={},n.e=e=>Promise.all(Object.keys(n.f).reduce(((t,o)=>(n.f[o](e,t),t)),[])),n.u=e=>e+".output.js",n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),n.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.p="dist/",e={792:0},t=t=>{var o,r,{__webpack_ids__:i,__webpack_modules__:a,__webpack_runtime__:s}=t,u=0;for(o in a)n.o(a,o)&&(n.m[o]=a[o]);for(s&&s(n);u<i.length;u++)r=i[u],n.o(e,r)&&e[r]&&e[r][0](),e[i[u]]=0},n.f.j=(o,r)=>{var i=n.o(e,o)?e[o]:void 0;if(0!==i)if(i)r.push(i[1]);else{var a=import(n.p+n.u(o)).then(t,(t=>{throw 0!==e[o]&&(e[o]=void 0),t}));a=Promise.race([a,new Promise((t=>i=e[o]=[t]))]),r.push(i[1]=a)}};const i=e=>console.log(e);setTimeout((async()=>{const e=await n.e(481).then(n.bind(n,481));i(e.value),e.increment(),e.increment(),e.increment(),i(e.value),await(async()=>{(await n.e(481).then(n.bind(n,481))).reset()})(),i(e.value)}),100);
|
2021-06-23 19:58:40 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
# Info
|
|
|
|
|
|
|
|
## Unoptimized
|
|
|
|
|
|
|
|
```
|
2025-05-28 22:41:15 +08:00
|
|
|
asset output.js 6.6 KiB [emitted] [javascript module] (name: main)
|
2025-04-25 01:57:25 +08:00
|
|
|
asset 1.output.js 1.38 KiB [emitted] [javascript module]
|
2025-05-28 22:41:15 +08:00
|
|
|
chunk (runtime: main) output.js (main) 420 bytes (javascript) 3.04 KiB (runtime) [entry] [rendered]
|
2021-06-23 19:58:40 +08:00
|
|
|
> ./example.js main
|
2025-05-28 22:41:15 +08:00
|
|
|
runtime modules 3.04 KiB 7 modules
|
2021-06-23 19:58:40 +08:00
|
|
|
./example.js + 1 modules 420 bytes [built] [code generated]
|
|
|
|
[no exports]
|
|
|
|
[no exports used]
|
|
|
|
entry ./example.js main
|
|
|
|
used as library export
|
|
|
|
chunk (runtime: main) 1.output.js 146 bytes [rendered]
|
|
|
|
> ./counter ./methods.js 2:8-27
|
|
|
|
> ./counter ./example.js 4:23-42
|
|
|
|
./counter.js 146 bytes [built] [code generated]
|
|
|
|
[exports: decrement, increment, reset, value]
|
|
|
|
import() ./counter ./example.js + 1 modules ./example.js 4:23-42
|
|
|
|
import() ./counter ./example.js + 1 modules ./methods.js 2:8-27
|
2025-04-29 02:11:48 +08:00
|
|
|
webpack X.X.X compiled successfully
|
2021-06-23 19:58:40 +08:00
|
|
|
```
|
|
|
|
|
|
|
|
## Production mode
|
|
|
|
|
|
|
|
```
|
2025-04-25 01:57:25 +08:00
|
|
|
asset output.js 1.2 KiB [emitted] [javascript module] [minimized] (name: main)
|
|
|
|
asset 481.output.js 249 bytes [emitted] [javascript module] [minimized]
|
|
|
|
chunk (runtime: main) 481.output.js 146 bytes [rendered]
|
2021-06-23 19:58:40 +08:00
|
|
|
> ./counter ./methods.js 2:8-27
|
|
|
|
> ./counter ./example.js 4:23-42
|
|
|
|
./counter.js 146 bytes [built] [code generated]
|
|
|
|
[exports: decrement, increment, reset, value]
|
|
|
|
import() ./counter ./example.js + 1 modules ./example.js 4:23-42
|
|
|
|
import() ./counter ./example.js + 1 modules ./methods.js 2:8-27
|
2025-05-28 22:41:15 +08:00
|
|
|
chunk (runtime: main) output.js (main) 420 bytes (javascript) 3.04 KiB (runtime) [entry] [rendered]
|
2025-04-25 01:57:25 +08:00
|
|
|
> ./example.js main
|
2025-05-28 22:41:15 +08:00
|
|
|
runtime modules 3.04 KiB 7 modules
|
2025-04-25 01:57:25 +08:00
|
|
|
./example.js + 1 modules 420 bytes [built] [code generated]
|
|
|
|
[no exports]
|
|
|
|
[no exports used]
|
|
|
|
entry ./example.js main
|
|
|
|
used as library export
|
2025-04-29 02:11:48 +08:00
|
|
|
webpack X.X.X compiled successfully
|
2021-06-23 19:58:40 +08:00
|
|
|
```
|