2021-06-28 18:30:25 +08:00
# example.js
```javascript
document.body.innerHTML = `
< pre id = "history" > < / pre >
< form >
< input id = "message" type = "text" >
< button id = "send" > Send Message< / button >
< / form >
< p > Computing fibonacci without worker:< / p >
< input id = "fib1" type = "number" >
< pre id = "output1" > < / pre >
< p > Computing fibonacci with worker:< / p >
< input id = "fib2" type = "number" >
< pre id = "output2" > < / pre >
`;
const history = document.getElementById("history");
const message = document.getElementById("message");
const send = document.getElementById("send");
const fib1 = document.getElementById("fib1");
const output1 = document.getElementById("output1");
const fib2 = document.getElementById("fib2");
const output2 = document.getElementById("output2");
/// CHAT with shared worker ///
const chatWorker = new SharedWorker(
new URL("./chat-worker.js", import.meta.url),
{
name: "chat",
type: "module"
}
);
let historyTimeout;
const scheduleUpdateHistory = () => {
clearTimeout(historyTimeout);
historyTimeout = setTimeout(() => {
chatWorker.port.postMessage({ type: "history" });
}, 1000);
};
scheduleUpdateHistory();
const from = `User ${Math.floor(Math.random() * 10000)}` ;
send.addEventListener("click", e => {
chatWorker.port.postMessage({
type: "message",
content: message.value,
from
});
message.value = "";
message.focus();
e.preventDefault();
});
chatWorker.port.onmessage = event => {
const msg = event.data;
switch (msg.type) {
case "history":
history.innerText = msg.history.join("\n");
scheduleUpdateHistory();
break;
}
};
/// FIBONACCI without worker ///
fib1.addEventListener("change", async () => {
try {
const value = parseInt(fib1.value, 10);
const { fibonacci } = await import("./fibonacci");
const result = fibonacci(value);
output1.innerText = `fib(${value}) = ${result}` ;
} catch (e) {
output1.innerText = e.message;
}
});
/// FIBONACCI with worker ///
const fibWorker = new Worker(new URL("./fib-worker.js", import.meta.url), {
name: "fibonacci",
type: "module"
/* webpackEntryOptions: { filename: "workers/[name].js" } */
});
fib2.addEventListener("change", () => {
try {
const value = parseInt(fib2.value, 10);
fibWorker.postMessage(`${value}`);
} catch (e) {
output2.innerText = e.message;
}
});
fibWorker.onmessage = event => {
output2.innerText = event.data;
};
```
# fib-worker.js
```javascript
onmessage = async event => {
const { fibonacci } = await import("./fibonacci");
const value = JSON.parse(event.data);
postMessage(`fib(${value}) = ${fibonacci(value)}`);
};
```
# fibonacci.js
```javascript
export function fibonacci(n) {
return n < 1 ? 0 : n < = 2 ? 1 : fibonacci ( n - 1 ) + fibonacci ( n - 2 ) ;
}
```
# chat-worker.js
```javascript
onconnect = function (e) {
for (const port of e.ports) {
port.onmessage = async event => {
const msg = event.data;
switch (msg.type) {
case "message":
const { add } = await import("./chat-module");
add(msg.content, msg.from);
// fallthrough
case "history":
const { history } = await import("./chat-module");
port.postMessage({
type: "history",
history
});
break;
}
};
}
};
```
# chat-module.js
```javascript
export const history = [];
export const add = (content, from) => {
if (history.length > 10) history.shift();
history.push(`${from}: ${content}`);
};
```
# dist/main.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 not based on template
2025-04-25 01:57:25 +08:00
/******/ if (chunkId === 721) return "workers/fibonacci.js";
2021-06-28 18:30:25 +08:00
/******/ // return url for filenames based on template
2025-04-25 01:57:25 +08:00
/******/ return "" + (chunkId === 377 ? "chat" : chunkId) + ".js";
2021-06-28 18:30:25 +08:00
/******/ };
/******/ })();
/******/
/******/ /* 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 });
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/publicPath */
/******/ (() => {
/******/ __webpack_require__ .p = "/dist/";
/******/ })();
/******/
/******/ /* webpack/runtime/import chunk loading */
/******/ (() => {
/******/ __webpack_require__ .b = new URL("./", import.meta.url);
/******/
/******/ // 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-28 18:30:25 +08:00
/******/ var installedChunks = {
2025-04-25 01:57:25 +08:00
/******/ 792: 0
2021-06-28 18:30:25 +08:00
/******/ };
/******/
2021-08-20 14:12:50 +08:00
/******/ var installChunk = (data) => {
2025-07-28 19:55:53 +08:00
/******/ var {__webpack_esm_ids__, __webpack_esm_modules__ , __webpack_esm_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-07-28 19:55:53 +08:00
/******/ for(moduleId in __webpack_esm_modules__ ) {
/******/ if(__webpack_require__.o(__webpack_esm_modules__, moduleId)) {
/******/ __webpack_require__ .m[moduleId] = __webpack_esm_modules__ [moduleId];
2021-08-20 14:12:50 +08:00
/******/ }
/******/ }
2025-07-28 19:55:53 +08:00
/******/ if(__webpack_esm_runtime__) __webpack_esm_runtime__ (__webpack_require__);
/******/ for(;i < __webpack_esm_ids__ .length ; i ++) {
/******/ chunkId = __webpack_esm_ids__ [i];
2021-08-20 14:12:50 +08:00
/******/ if(__webpack_require__.o(installedChunks, chunkId) & & installedChunks[chunkId]) {
/******/ installedChunks[chunkId][0]();
/******/ }
2025-07-28 19:55:53 +08:00
/******/ installedChunks[__webpack_esm_ids__[i]] = 0;
2021-08-20 14:12:50 +08:00
/******/ }
/******/
/******/ }
/******/
2021-06-28 18:30:25 +08:00
/******/ __webpack_require__ .f.j = (chunkId, promises) => {
/******/ // import() chunk loading for javascript
/******/ 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-28 18:30:25 +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-28 18:30:25 +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-28 18:30:25 +08:00
/******/ // no on chunks loaded
2025-07-01 18:16:11 +08:00
/******/ // no HMR
/******/
/******/ // no HMR manifest
2021-06-28 18:30:25 +08:00
/******/ })();
/******/
/************************************************************************/
```
< / details >
``` js
var __webpack_exports__ = {};
/*!********************!*\
!*** ./example.js ** *!
\********************/
/*! unknown exports (runtime-defined) */
/*! runtime requirements: __webpack_require__ .p, __webpack_require__ .b, __webpack_require__ .u, __webpack_require__ .e, __webpack_require__ , __webpack_require__ .* */
document.body.innerHTML = `
< pre id = "history" > < / pre >
< form >
< input id = "message" type = "text" >
< button id = "send" > Send Message< / button >
< / form >
< p > Computing fibonacci without worker:< / p >
< input id = "fib1" type = "number" >
< pre id = "output1" > < / pre >
< p > Computing fibonacci with worker:< / p >
< input id = "fib2" type = "number" >
< pre id = "output2" > < / pre >
`;
const history = document.getElementById("history");
const message = document.getElementById("message");
const send = document.getElementById("send");
const fib1 = document.getElementById("fib1");
const output1 = document.getElementById("output1");
const fib2 = document.getElementById("fib2");
const output2 = document.getElementById("output2");
/// CHAT with shared worker ///
const chatWorker = new SharedWorker(
2025-04-25 01:57:25 +08:00
new URL(/* worker import */ __webpack_require__ .p + __webpack_require__ .u(377), __webpack_require__ .b),
2021-06-28 18:30:25 +08:00
{
name: "chat",
type: "module"
}
);
let historyTimeout;
const scheduleUpdateHistory = () => {
clearTimeout(historyTimeout);
historyTimeout = setTimeout(() => {
chatWorker.port.postMessage({ type: "history" });
}, 1000);
};
scheduleUpdateHistory();
const from = `User ${Math.floor(Math.random() * 10000)}` ;
send.addEventListener("click", e => {
chatWorker.port.postMessage({
type: "message",
content: message.value,
from
});
message.value = "";
message.focus();
e.preventDefault();
});
chatWorker.port.onmessage = event => {
const msg = event.data;
switch (msg.type) {
case "history":
history.innerText = msg.history.join("\n");
scheduleUpdateHistory();
break;
}
};
/// FIBONACCI without worker ///
fib1.addEventListener("change", async () => {
try {
const value = parseInt(fib1.value, 10);
2025-04-25 01:57:25 +08:00
const { fibonacci } = await __webpack_require__ .e(/*! import() */ 129).then(__webpack_require__.bind(__webpack_require__, /* ! ./fibonacci */ 3));
2021-06-28 18:30:25 +08:00
const result = fibonacci(value);
output1.innerText = `fib(${value}) = ${result}` ;
} catch (e) {
output1.innerText = e.message;
}
});
/// FIBONACCI with worker ///
2025-04-25 01:57:25 +08:00
const fibWorker = new Worker(new URL(/* worker import */ __webpack_require__ .p + __webpack_require__ .u(721), __webpack_require__ .b), {
2021-06-28 18:30:25 +08:00
name: "fibonacci",
type: "module"
/* webpackEntryOptions: { filename: "workers/[name].js" } */
});
fib2.addEventListener("change", () => {
try {
const value = parseInt(fib2.value, 10);
fibWorker.postMessage(`${value}`);
} catch (e) {
output2.innerText = e.message;
}
});
fibWorker.onmessage = event => {
output2.innerText = event.data;
};
```
# dist/chat.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 + ".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-28 18:30:25 +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-28 18:30:25 +08:00
/******/ var installedChunks = {
2025-04-25 01:57:25 +08:00
/******/ 377: 0
2021-06-28 18:30:25 +08:00
/******/ };
/******/
2021-08-20 14:12:50 +08:00
/******/ var installChunk = (data) => {
2025-07-28 19:55:53 +08:00
/******/ var {__webpack_esm_ids__, __webpack_esm_modules__ , __webpack_esm_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-07-28 19:55:53 +08:00
/******/ for(moduleId in __webpack_esm_modules__ ) {
/******/ if(__webpack_require__.o(__webpack_esm_modules__, moduleId)) {
/******/ __webpack_require__ .m[moduleId] = __webpack_esm_modules__ [moduleId];
2021-08-20 14:12:50 +08:00
/******/ }
/******/ }
2025-07-28 19:55:53 +08:00
/******/ if(__webpack_esm_runtime__) __webpack_esm_runtime__ (__webpack_require__);
/******/ for(;i < __webpack_esm_ids__ .length ; i ++) {
/******/ chunkId = __webpack_esm_ids__ [i];
2021-08-20 14:12:50 +08:00
/******/ if(__webpack_require__.o(installedChunks, chunkId) & & installedChunks[chunkId]) {
/******/ installedChunks[chunkId][0]();
/******/ }
2025-07-28 19:55:53 +08:00
/******/ installedChunks[__webpack_esm_ids__[i]] = 0;
2021-08-20 14:12:50 +08:00
/******/ }
/******/
/******/ }
/******/
2021-06-28 18:30:25 +08:00
/******/ __webpack_require__ .f.j = (chunkId, promises) => {
/******/ // import() chunk loading for javascript
/******/ 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-28 18:30:25 +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-28 18:30:25 +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-28 18:30:25 +08:00
/******/ // no on chunks loaded
2025-07-01 18:16:11 +08:00
/******/ // no HMR
/******/
/******/ // no HMR manifest
2021-06-28 18:30:25 +08:00
/******/ })();
/******/
/************************************************************************/
```
< / details >
``` js
var __webpack_exports__ = {};
/*!************************!*\
!*** ./chat-worker.js ** *!
\************************/
/*! unknown exports (runtime-defined) */
/*! runtime requirements: __webpack_require__ .e, __webpack_require__ , __webpack_require__ .* */
onconnect = function (e) {
for (const port of e.ports) {
port.onmessage = async event => {
const msg = event.data;
switch (msg.type) {
case "message":
2025-04-25 01:57:25 +08:00
const { add } = await __webpack_require__ .e(/*! import() */ 936).then(__webpack_require__.bind(__webpack_require__, /* ! ./chat-module */ 4));
2021-06-28 18:30:25 +08:00
add(msg.content, msg.from);
// fallthrough
case "history":
2025-04-25 01:57:25 +08:00
const { history } = await __webpack_require__ .e(/*! import() */ 936).then(__webpack_require__.bind(__webpack_require__, /* ! ./chat-module */ 4));
2021-06-28 18:30:25 +08:00
port.postMessage({
type: "history",
history
});
break;
}
};
}
};
```
```javascript
2025-07-28 19:55:53 +08:00
var e,o,t={},r={};function s(e){var o=r[e];if(void 0!==o)return o.exports;var n=r[e]={exports:{}};return t[e](n,n.exports,s),n.exports}s.m=t,s.d=(e,o)=>{for(var t in o)s.o(o,t)& & !s.o(e,t)& & Object.defineProperty(e,t,{enumerable:!0,get:o[t]})},s.f={},s.e=e=>Promise.all(Object.keys(s.f).reduce((o,t)=>(s.f[t](e,o),o),[])),s.u=e=>e+".js",s.o=(e,o)=>Object.prototype.hasOwnProperty.call(e,o),s.p="/dist/",e={377:0},o=o=>{var t,r,{__webpack_esm_ids__:n,__webpack_esm_modules__:a,__webpack_esm_runtime__:i}=o,c=0;for(t in a)s.o(a,t)&&(s.m[t]=a[t]); for(i&&i(s); c< n.length ; c + + ) r = n[c],s.o(e,r)&&e[r]&&e[r][0](),e[n[c]]=0},s.f.j=(t,r)= > {var n=s.o(e,t)?e[t]:void 0;if(0!==n)if(n)r.push(n[1]);else{var a=import(s.p+s.u(t)).then(o,o=>{throw 0!==e[t]& & (e[t]=void 0),o});a=Promise.race([a,new Promise(o=>n=e[t]=[o])]),r.push(n[1]=a)}},onconnect=function(e){for(const o of e.ports)o.onmessage=async e=>{const t=e.data;switch(t.type){case"message":const{add:e}=await s.e(936).then(s.bind(s,936));e(t.content,t.from);case"history":const{history:r}=await s.e(936).then(s.bind(s,936));o.postMessage({type:"history",history:r})}}};
2021-06-28 18:30:25 +08:00
```
# dist/workers/fibonacci.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 + ".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-28 18:30:25 +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-28 18:30:25 +08:00
/******/ var installedChunks = {
2025-04-25 01:57:25 +08:00
/******/ 721: 0
2021-06-28 18:30:25 +08:00
/******/ };
/******/
2021-08-20 14:12:50 +08:00
/******/ var installChunk = (data) => {
2025-07-28 19:55:53 +08:00
/******/ var {__webpack_esm_ids__, __webpack_esm_modules__ , __webpack_esm_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-07-28 19:55:53 +08:00
/******/ for(moduleId in __webpack_esm_modules__ ) {
/******/ if(__webpack_require__.o(__webpack_esm_modules__, moduleId)) {
/******/ __webpack_require__ .m[moduleId] = __webpack_esm_modules__ [moduleId];
2021-08-20 14:12:50 +08:00
/******/ }
/******/ }
2025-07-28 19:55:53 +08:00
/******/ if(__webpack_esm_runtime__) __webpack_esm_runtime__ (__webpack_require__);
/******/ for(;i < __webpack_esm_ids__ .length ; i ++) {
/******/ chunkId = __webpack_esm_ids__ [i];
2021-08-20 14:12:50 +08:00
/******/ if(__webpack_require__.o(installedChunks, chunkId) & & installedChunks[chunkId]) {
/******/ installedChunks[chunkId][0]();
/******/ }
2025-07-28 19:55:53 +08:00
/******/ installedChunks[__webpack_esm_ids__[i]] = 0;
2021-08-20 14:12:50 +08:00
/******/ }
/******/
/******/ }
/******/
2021-06-28 18:30:25 +08:00
/******/ __webpack_require__ .f.j = (chunkId, promises) => {
/******/ // import() chunk loading for javascript
/******/ 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-28 18:30:25 +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-28 18:30:25 +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-28 18:30:25 +08:00
/******/ // no on chunks loaded
2025-07-01 18:16:11 +08:00
/******/ // no HMR
/******/
/******/ // no HMR manifest
2021-06-28 18:30:25 +08:00
/******/ })();
/******/
/************************************************************************/
```
< / details >
``` js
var __webpack_exports__ = {};
/*!***********************!*\
!*** ./fib-worker.js ** *!
\***********************/
/*! unknown exports (runtime-defined) */
/*! runtime requirements: __webpack_require__ .e, __webpack_require__ , __webpack_require__ .* */
onmessage = async event => {
2025-04-25 01:57:25 +08:00
const { fibonacci } = await __webpack_require__ .e(/*! import() */ 129).then(__webpack_require__.bind(__webpack_require__, /* ! ./fibonacci */ 3));
2021-06-28 18:30:25 +08:00
const value = JSON.parse(event.data);
postMessage(`fib(${value}) = ${fibonacci(value)}`);
};
```
```javascript
2025-07-28 19:55:53 +08:00
var e,r,o={},s={};function t(e){var r=s[e];if(void 0!==r)return r.exports;var a=s[e]={exports:{}};return o[e](a,a.exports,t),a.exports}t.m=o,t.d=(e,r)=>{for(var o in r)t.o(r,o)& & !t.o(e,o)& & Object.defineProperty(e,o,{enumerable:!0,get:r[o]})},t.f={},t.e=e=>Promise.all(Object.keys(t.f).reduce((r,o)=>(t.f[o](e,r),r),[])),t.u=e=>e+".js",t.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),t.p="/dist/",e={721:0},r=r=>{var o,s,{__webpack_esm_ids__:a,__webpack_esm_modules__:i,__webpack_esm_runtime__:n}=r,p=0;for(o in i)t.o(i,o)&&(t.m[o]=i[o]); for(n&&n(t); p< a.length ; p + + ) s = a[p],t.o(e,s)&&e[s]&&e[s][0](),e[a[p]]=0},t.f.j=(o,s)= > {var a=t.o(e,o)?e[o]:void 0;if(0!==a)if(a)s.push(a[1]);else{var i=import(t.p+t.u(o)).then(r,r=>{throw 0!==e[o]& & (e[o]=void 0),r});i=Promise.race([i,new Promise(r=>a=e[o]=[r])]),s.push(a[1]=i)}},onmessage=async e=>{const{fibonacci:r}=await t.e(129).then(t.bind(t,129)),o=JSON.parse(e.data);postMessage(`fib(${o}) = ${r(o)}`)};
2021-06-28 18:30:25 +08:00
```
# dist/129.js
```javascript
2025-07-28 19:55:53 +08:00
export const __webpack_esm_id__ = 129;
export const __webpack_esm_ids__ = [129];
export const __webpack_esm_modules__ = {
2021-06-28 18:30:25 +08:00
2025-04-25 01:57:25 +08:00
/***/ 3:
2021-06-28 18:30:25 +08:00
/*!**********************!*\
!*** ./fibonacci.js ** *!
\**********************/
/*! namespace exports */
/*! export fibonacci [provided] [no usage info] [missing usage info prevents renaming] */
/*! other exports [not provided] [no usage info] */
/*! runtime requirements: __webpack_require__ .r, __webpack_exports__ , __webpack_require__ .d, __webpack_require__ .* */
/***/ ((__unused_webpack_module, __webpack_exports__ , __webpack_require__ ) => {
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__ .d(__webpack_exports__, {
2025-04-25 01:57:25 +08:00
/* harmony export */ fibonacci: () => (/* binding */ fibonacci)
2021-06-28 18:30:25 +08:00
/* harmony export */ });
function fibonacci(n) {
return n < 1 ? 0 : n < = 2 ? 1 : fibonacci ( n - 1 ) + fibonacci ( n - 2 ) ;
}
/***/ })
};
```
# Info
## Unoptimized
```
2025-07-28 19:55:53 +08:00
asset main.js 8.83 KiB [emitted] [javascript module] (name: main)
asset chat.js 6.75 KiB [emitted] [javascript module] (name: chat)
asset workers/fibonacci.js 6.39 KiB [emitted] [javascript module] (name: fibonacci)
asset 936.js 1.05 KiB [emitted] [javascript module]
asset 129.js 893 bytes [emitted] [javascript module]
2021-06-28 18:30:25 +08:00
chunk (runtime: 9a81d90cfd0dfd13d748, main) 129.js 103 bytes [rendered]
> ./fibonacci ./example.js 70:30-51
> ./fibonacci ./fib-worker.js 2:29-50
./fibonacci.js 103 bytes [built] [code generated]
[exports: fibonacci]
[used exports unknown]
import() ./fibonacci ./example.js 70:30-51
import() ./fibonacci ./fib-worker.js 2:29-50
2025-07-28 19:55:53 +08:00
chunk (runtime: 1fad8bf8de78b0a77bfd) chat.js (chat) 442 bytes (javascript) 3.11 KiB (runtime) [entry] [rendered]
2025-04-25 01:57:25 +08:00
> ./example.js 25:19-31:1
2025-07-28 19:55:53 +08:00
runtime modules 3.11 KiB 7 modules
2025-04-25 01:57:25 +08:00
./chat-worker.js 442 bytes [built] [code generated]
[used exports unknown]
new Worker() ./chat-worker.js ./example.js 25:19-31:1
2025-07-28 19:55:53 +08:00
chunk (runtime: 9a81d90cfd0dfd13d748) workers/fibonacci.js (fibonacci) 176 bytes (javascript) 3.11 KiB (runtime) [entry] [rendered]
2025-04-25 01:57:25 +08:00
> ./example.js 80:18-84:2
2025-07-28 19:55:53 +08:00
runtime modules 3.11 KiB 7 modules
2025-04-25 01:57:25 +08:00
./fib-worker.js 176 bytes [built] [code generated]
[used exports unknown]
new Worker() ./fib-worker.js ./example.js 80:18-84:2
2025-07-28 19:55:53 +08:00
chunk (runtime: main) main.js (main) 2.25 KiB (javascript) 3.28 KiB (runtime) [entry] [rendered]
2021-06-28 18:30:25 +08:00
> ./example.js main
2025-07-28 19:55:53 +08:00
runtime modules 3.28 KiB 7 modules
2021-06-28 18:30:25 +08:00
./example.js 2.25 KiB [built] [code generated]
[used exports unknown]
entry ./example.js main
2025-04-25 01:57:25 +08:00
chunk (runtime: 1fad8bf8de78b0a77bfd) 936.js 152 bytes [rendered]
2021-06-28 18:30:25 +08:00
> ./chat-module ./chat-worker.js 11:31-54
> ./chat-module ./chat-worker.js 7:27-50
./chat-module.js 152 bytes [built] [code generated]
[exports: add, history]
[used exports unknown]
import() ./chat-module ./chat-worker.js 7:27-50
import() ./chat-module ./chat-worker.js 11:31-54
2025-04-29 02:11:48 +08:00
webpack X.X.X compiled successfully
2021-06-28 18:30:25 +08:00
```
## Production mode
```
2025-07-28 19:55:53 +08:00
asset main.js 2.36 KiB [emitted] [javascript module] [minimized] (name: main)
asset chat.js 1.08 KiB [emitted] [javascript module] [minimized] (name: chat)
asset workers/fibonacci.js 951 bytes [emitted] [javascript module] [minimized] (name: fibonacci)
asset 936.js 228 bytes [emitted] [javascript module] [minimized]
asset 129.js 202 bytes [emitted] [javascript module] [minimized]
2021-06-28 18:30:25 +08:00
chunk (runtime: 9a81d90cfd0dfd13d748, main) 129.js 103 bytes [rendered]
> ./fibonacci ./fib-worker.js 2:29-50
2025-04-25 01:57:25 +08:00
> ./fibonacci ./example.js 70:30-51
2021-06-28 18:30:25 +08:00
./fibonacci.js 103 bytes [built] [code generated]
[exports: fibonacci]
2025-04-25 01:57:25 +08:00
[all exports used]
2021-06-28 18:30:25 +08:00
import() ./fibonacci ./example.js 70:30-51
import() ./fibonacci ./fib-worker.js 2:29-50
2025-07-28 19:55:53 +08:00
chunk (runtime: 1fad8bf8de78b0a77bfd) chat.js (chat) 442 bytes (javascript) 2.84 KiB (runtime) [entry] [rendered]
2025-04-25 01:57:25 +08:00
> ./example.js 25:19-31:1
2025-07-28 19:55:53 +08:00
runtime modules 2.84 KiB 6 modules
2025-04-25 01:57:25 +08:00
./chat-worker.js 442 bytes [built] [code generated]
[no exports used]
new Worker() ./chat-worker.js ./example.js 25:19-31:1
2025-07-28 19:55:53 +08:00
chunk (runtime: 9a81d90cfd0dfd13d748) workers/fibonacci.js (fibonacci) 176 bytes (javascript) 2.84 KiB (runtime) [entry] [rendered]
2025-04-25 01:57:25 +08:00
> ./example.js 80:18-84:2
2025-07-28 19:55:53 +08:00
runtime modules 2.84 KiB 6 modules
2025-04-25 01:57:25 +08:00
./fib-worker.js 176 bytes [built] [code generated]
[no exports used]
new Worker() ./fib-worker.js ./example.js 80:18-84:2
2025-07-28 19:55:53 +08:00
chunk (runtime: main) main.js (main) 2.25 KiB (javascript) 3.01 KiB (runtime) [entry] [rendered]
2021-06-28 18:30:25 +08:00
> ./example.js main
2025-07-28 19:55:53 +08:00
runtime modules 3.01 KiB 6 modules
2021-06-28 18:30:25 +08:00
./example.js 2.25 KiB [built] [code generated]
[no exports used]
entry ./example.js main
2025-04-25 01:57:25 +08:00
chunk (runtime: 1fad8bf8de78b0a77bfd) 936.js 152 bytes [rendered]
2021-06-28 18:30:25 +08:00
> ./chat-module ./chat-worker.js 11:31-54
> ./chat-module ./chat-worker.js 7:27-50
./chat-module.js 152 bytes [built] [code generated]
[exports: add, history]
2025-04-25 01:57:25 +08:00
[all exports used]
2021-06-28 18:30:25 +08:00
import() ./chat-module ./chat-worker.js 7:27-50
import() ./chat-module ./chat-worker.js 11:31-54
2025-04-29 02:11:48 +08:00
webpack X.X.X compiled successfully
2021-06-28 18:30:25 +08:00
```