2020-09-08 00:02:14 +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),
{
2021-03-22 21:30:17 +08:00
name: "chat",
type: "module"
2020-09-08 00:02:14 +08:00
}
);
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), {
2021-03-22 21:30:17 +08:00
name: "fibonacci",
type: "module"
2020-09-08 00:02:14 +08:00
/* 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
import { history, add } from "./chat-module";
onconnect = function (e) {
for (const port of e.ports) {
port.onmessage = event => {
const msg = event.data;
switch (msg.type) {
case "message":
add(msg.content, msg.from);
// fallthrough
case "history":
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
/******/ (() => { // webpackBootstrap
/******/ 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
2021-03-22 21:30:17 +08:00
/******/ var cachedModule = __webpack_module_cache__ [moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
2020-09-08 00:02:14 +08:00
/******/ }
/******/ // 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";
2020-09-08 00:02:14 +08:00
/******/ // return url for filenames based on template
2025-04-25 01:57:25 +08:00
/******/ return "" + (chunkId === 377 ? "chat" : chunkId) + ".js";
2020-09-08 00:02:14 +08:00
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
2021-03-22 21:30:17 +08:00
/******/ __webpack_require__ .o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
2020-09-08 00:02:14 +08:00
/******/ })();
/******/
/******/ /* webpack/runtime/load script */
/******/ (() => {
/******/ var inProgress = {};
/******/ // data-webpack is not used as build has no uniqueName
/******/ // loadScript function to load a script via script tag
2021-03-22 21:30:17 +08:00
/******/ __webpack_require__ .l = (url, done, key, chunkId) => {
2020-09-08 00:02:14 +08:00
/******/ if(inProgress[url]) { inProgress[url].push(done); return; }
/******/ var script, needAttach;
/******/ if(key !== undefined) {
/******/ var scripts = document.getElementsByTagName("script");
/******/ for(var i = 0; i < script s . length ; i + + ) {
/******/ var s = scripts[i];
/******/ if(s.getAttribute("src") == url) { script = s; break; }
/******/ }
/******/ }
/******/ if(!script) {
/******/ needAttach = true;
/******/ script = document.createElement('script');
/******/
/******/ script.charset = 'utf-8';
/******/ if (__webpack_require__.nc) {
/******/ script.setAttribute("nonce", __webpack_require__ .nc);
/******/ }
/******/
2025-04-25 01:57:25 +08:00
/******/
2020-09-08 00:02:14 +08:00
/******/ script.src = url;
/******/ }
/******/ inProgress[url] = [done];
/******/ var onScriptComplete = (prev, event) => {
/******/ // avoid mem leaks in IE.
/******/ script.onerror = script.onload = null;
/******/ clearTimeout(timeout);
/******/ var doneFns = inProgress[url];
/******/ delete inProgress[url];
/******/ script.parentNode & & script.parentNode.removeChild(script);
2021-03-22 21:30:17 +08:00
/******/ doneFns & & doneFns.forEach((fn) => (fn(event)));
2020-09-08 00:02:14 +08:00
/******/ if(prev) return prev(event);
/******/ }
/******/ var timeout = setTimeout(onScriptComplete.bind(null, undefined, { type: 'timeout', target: script }), 120000);
/******/ script.onerror = onScriptComplete.bind(null, script.onerror);
/******/ script.onload = onScriptComplete.bind(null, script.onload);
/******/ needAttach & & document.head.appendChild(script);
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/publicPath */
/******/ (() => {
2021-03-22 21:30:17 +08:00
/******/ __webpack_require__ .p = "/dist/";
2020-09-08 00:02:14 +08:00
/******/ })();
/******/
/******/ /* webpack/runtime/jsonp chunk loading */
/******/ (() => {
2025-10-06 20:29:40 +08:00
/******/ __webpack_require__ .b = (typeof document !== 'undefined' && document.baseURI) || self.location.href;
2020-09-08 00:02:14 +08:00
/******/
/******/ // object to store loaded and loading chunks
/******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
2021-03-22 21:30:17 +08:00
/******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded
2020-09-08 00:02:14 +08:00
/******/ var installedChunks = {
2025-04-25 01:57:25 +08:00
/******/ 792: 0
2020-09-08 00:02:14 +08:00
/******/ };
/******/
/******/ __webpack_require__ .f.j = (chunkId, promises) => {
/******/ // JSONP 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[2]);
/******/ } else {
/******/ if(true) { // all chunks have JS
/******/ // setup Promise in chunk cache
2021-03-22 21:30:17 +08:00
/******/ var promise = new Promise((resolve, reject) => (installedChunkData = installedChunks[chunkId] = [resolve, reject]));
2020-09-08 00:02:14 +08:00
/******/ promises.push(installedChunkData[2] = promise);
/******/
/******/ // start chunk loading
/******/ var url = __webpack_require__ .p + __webpack_require__ .u(chunkId);
/******/ // create error before stack unwound to get useful stacktrace later
/******/ var error = new Error();
/******/ var loadingEnded = (event) => {
/******/ if(__webpack_require__.o(installedChunks, chunkId)) {
/******/ installedChunkData = installedChunks[chunkId];
/******/ if(installedChunkData !== 0) installedChunks[chunkId] = undefined;
/******/ if(installedChunkData) {
/******/ var errorType = event & & (event.type === 'load' ? 'missing' : event.type);
/******/ var realSrc = event & & event.target & & event.target.src;
/******/ error.message = 'Loading chunk ' + chunkId + ' failed.\n(' + errorType + ': ' + realSrc + ')';
/******/ error.name = 'ChunkLoadError';
/******/ error.type = errorType;
/******/ error.request = realSrc;
/******/ installedChunkData[1](error);
/******/ }
/******/ }
/******/ };
2021-03-22 21:30:17 +08:00
/******/ __webpack_require__ .l(url, loadingEnded, "chunk-" + chunkId, chunkId);
2025-04-25 01:57:25 +08:00
/******/ }
2020-09-08 00:02:14 +08:00
/******/ }
/******/ }
/******/ };
/******/
/******/ // no prefetching
/******/
/******/ // no preloaded
/******/
/******/ // no HMR
/******/
/******/ // no HMR manifest
/******/
2021-03-22 21:30:17 +08:00
/******/ // no on chunks loaded
2020-09-08 00:02:14 +08:00
/******/
/******/ // install a JSONP callback for chunk loading
2020-12-11 17:29:32 +08:00
/******/ var webpackJsonpCallback = (parentChunkLoadingFunction, data) => {
2020-09-08 00:02:14 +08:00
/******/ var [chunkIds, moreModules, runtime] = data;
/******/ // add "moreModules" to the modules object,
/******/ // then flag all "chunkIds" as loaded and fire callback
2021-03-22 21:30:17 +08:00
/******/ var moduleId, chunkId, i = 0;
2021-08-20 14:12:50 +08:00
/******/ if(chunkIds.some((id) => (installedChunks[id] !== 0))) {
/******/ for(moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__ .m[moduleId] = moreModules[moduleId];
/******/ }
2020-09-08 00:02:14 +08:00
/******/ }
2021-08-20 14:12:50 +08:00
/******/ if(runtime) var result = runtime(__webpack_require__);
2020-09-08 00:02:14 +08:00
/******/ }
2020-12-11 17:29:32 +08:00
/******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
2021-03-22 21:30:17 +08:00
/******/ for(;i < chunkIds.length ; i + + ) {
/******/ chunkId = chunkIds[i];
/******/ if(__webpack_require__.o(installedChunks, chunkId) & & installedChunks[chunkId]) {
/******/ installedChunks[chunkId][0]();
/******/ }
2023-04-08 06:23:22 +08:00
/******/ installedChunks[chunkId] = 0;
2020-09-08 00:02:14 +08:00
/******/ }
/******/
/******/ }
/******/
/******/ var chunkLoadingGlobal = self["webpackChunk"] = self["webpackChunk"] || [];
2020-12-11 17:29:32 +08:00
/******/ chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));
/******/ chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));
2020-09-08 00:02:14 +08:00
/******/ })();
/******/
/************************************************************************/
```
< / details >
``` js
2021-03-22 21:30:17 +08:00
var __webpack_exports__ = {};
2020-09-08 00:02:14 +08:00
/*!********************!*\
!*** ./example.js ** *!
\********************/
/*! unknown exports (runtime-defined) */
/*! runtime requirements: __webpack_require__ .p, __webpack_require__ .b, __webpack_require__ .u, __webpack_require__ .e, __webpack_require__ , __webpack_require__ .* */
/*! ModuleConcatenation bailout: Module is not an ECMAScript module */
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),
2020-09-08 00:02:14 +08:00
{
2021-03-22 21:30:17 +08:00
name: "chat",
type: undefined
2020-09-08 00:02:14 +08:00
}
);
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));
2020-09-08 00:02:14 +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-03-22 21:30:17 +08:00
name: "fibonacci",
type: undefined
2020-09-08 00:02:14 +08:00
/* 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
/******/ (() => { // webpackBootstrap
/******/ "use strict";
/*!************************************!*\
!*** ./chat-worker.js + 1 modules ** *!
\************************************/
/*! namespace exports */
/*! runtime requirements: */
2025-04-25 01:57:25 +08:00
;// ./chat-module.js
2020-09-08 00:02:14 +08:00
const chat_module_history = [];
const add = (content, from) => {
if (chat_module_history.length > 10) chat_module_history.shift();
chat_module_history.push(`${from}: ${content}`);
};
2025-04-25 01:57:25 +08:00
;// ./chat-worker.js
2020-09-08 00:02:14 +08:00
onconnect = function (e) {
for (const port of e.ports) {
port.onmessage = event => {
const msg = event.data;
switch (msg.type) {
case "message":
add(msg.content, msg.from);
// fallthrough
case "history":
port.postMessage({
type: "history",
history: chat_module_history
});
break;
}
};
}
};
/******/ })()
;
```
```javascript
(()=>{"use strict";const s=[];onconnect=function(t){for(const o of t.ports)o.onmessage=t=>{const e=t.data;switch(e.type){case"message":n=e.content,c=e.from,s.length>10& & s.shift(),s.push(`${c}: ${n}`);case"history":o.postMessage({type:"history",history:s})}var n,c}}})();
```
# dist/workers/fibonacci.js
```javascript
/******/ (() => { // webpackBootstrap
/******/ 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
2021-03-22 21:30:17 +08:00
/******/ var cachedModule = __webpack_module_cache__ [moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
2020-09-08 00:02:14 +08:00
/******/ }
/******/ // 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 */
/******/ (() => {
2021-03-22 21:30:17 +08:00
/******/ __webpack_require__ .o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
2020-09-08 00:02:14 +08:00
/******/ })();
/******/
/******/ /* webpack/runtime/publicPath */
/******/ (() => {
2021-03-22 21:30:17 +08:00
/******/ __webpack_require__ .p = "/dist/";
2020-09-08 00:02:14 +08:00
/******/ })();
/******/
/******/ /* webpack/runtime/importScripts chunk loading */
/******/ (() => {
/******/ // no baseURI
/******/
/******/ // object to store loaded chunks
/******/ // "1" means "already loaded"
/******/ var installedChunks = {
2025-04-25 01:57:25 +08:00
/******/ 721: 1
2020-09-08 00:02:14 +08:00
/******/ };
/******/
/******/ // importScripts chunk loading
2021-03-22 21:30:17 +08:00
/******/ var installChunk = (data) => {
2020-09-08 00:02:14 +08:00
/******/ var [chunkIds, moreModules, runtime] = data;
/******/ for(var moduleId in moreModules) {
/******/ if(__webpack_require__.o(moreModules, moduleId)) {
/******/ __webpack_require__ .m[moduleId] = moreModules[moduleId];
/******/ }
/******/ }
/******/ if(runtime) runtime(__webpack_require__);
/******/ while(chunkIds.length)
/******/ installedChunks[chunkIds.pop()] = 1;
/******/ parentChunkLoadingFunction(data);
/******/ };
/******/ __webpack_require__ .f.i = (chunkId, promises) => {
/******/ // "1" is the signal for "already loaded"
/******/ if(!installedChunks[chunkId]) {
2021-03-22 21:30:17 +08:00
/******/ if(true) { // all chunks have JS
/******/ importScripts(__webpack_require__.p + __webpack_require__ .u(chunkId));
/******/ }
2020-09-08 00:02:14 +08:00
/******/ }
/******/ };
/******/
/******/ var chunkLoadingGlobal = self["webpackChunk"] = self["webpackChunk"] || [];
/******/ var parentChunkLoadingFunction = chunkLoadingGlobal.push.bind(chunkLoadingGlobal);
2021-03-22 21:30:17 +08:00
/******/ chunkLoadingGlobal.push = installChunk;
2020-09-08 00:02:14 +08:00
/******/
/******/ // no HMR
/******/
/******/ // no HMR manifest
/******/ })();
/******/
/************************************************************************/
```
< / details >
``` js
2021-03-22 21:30:17 +08:00
var __webpack_exports__ = {};
2020-09-08 00:02:14 +08:00
/*!***********************!*\
!*** ./fib-worker.js ** *!
\***********************/
/*! unknown exports (runtime-defined) */
/*! runtime requirements: __webpack_require__ .e, __webpack_require__ , __webpack_require__ .* */
/*! ModuleConcatenation bailout: Module is not an ECMAScript module */
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));
2020-09-08 00:02:14 +08:00
const value = JSON.parse(event.data);
postMessage(`fib(${value}) = ${fibonacci(value)}`);
};
/******/ })()
;
```
```javascript
2025-07-01 18:16:11 +08:00
(()=>{var e={},r={};function o(t){var a=r[t];if(void 0!==a)return a.exports;var s=r[t]={exports:{}};return e[t](s,s.exports,o),s.exports}o.m=e,o.d=(e,r)=>{for(var t in r)o.o(r,t)& & !o.o(e,t)& & Object.defineProperty(e,t,{enumerable:!0,get:r[t]})},o.f={},o.e=e=>Promise.all(Object.keys(o.f).reduce((r,t)=>(o.f[t](e,r),r),[])),o.u=e=>e+".js",o.o=(e,r)=>Object.prototype.hasOwnProperty.call(e,r),o.p="/dist/",(()=>{var e={721:1};o.f.i=(r,t)=>{e[r]||importScripts(o.p+o.u(r))};var r=self.webpackChunk=self.webpackChunk||[],t=r.push.bind(r);r.push=r=>{var[a,s,p]=r;for(var n in s)o.o(s,n)&&(o.m[n]=s[n]); for(p&&p(o); a.length;)e[a.pop()]=1;t(r)}})(),onmessage=async e=>{const{fibonacci:r}=await o.e(129).then(o.bind(o,129)),t=JSON.parse(e.data);postMessage(`fib(${t}) = ${r(t)}`)}})();
2020-09-08 00:02:14 +08:00
```
# dist/129.js
```javascript
2021-08-20 14:12:50 +08:00
"use strict";
2020-09-08 00:02:14 +08:00
(self["webpackChunk"] = self["webpackChunk"] || []).push([[129],{
2025-04-25 01:57:25 +08:00
/***/ 3:
2020-09-08 00:02:14 +08:00
/*!**********************!*\
!*** ./fibonacci.js ** *!
\**********************/
/*! namespace exports */
2025-04-25 01:57:25 +08:00
/*! export fibonacci [provided] [used in main, 9a81d90cfd0dfd13d748] [usage prevents renaming] */
/*! runtime requirements: __webpack_exports__ , __webpack_require__ .d, __webpack_require__ .* */
2020-09-08 00:02:14 +08:00
/***/ ((__unused_webpack_module, __webpack_exports__ , __webpack_require__ ) => {
/* harmony export */ __webpack_require__ .d(__webpack_exports__, {
2025-04-25 01:57:25 +08:00
/* harmony export */ fibonacci: () => (/* binding */ fibonacci)
2020-09-08 00:02:14 +08:00
/* harmony export */ });
function fibonacci(n) {
return n < 1 ? 0 : n < = 2 ? 1 : fibonacci ( n - 1 ) + fibonacci ( n - 2 ) ;
}
/***/ })
}]);
```
# Info
## Unoptimized
```
2025-10-06 20:29:40 +08:00
asset main.js 11.9 KiB [emitted] (name: main)
2025-04-25 01:57:25 +08:00
asset workers/fibonacci.js 4.99 KiB [emitted] (name: fibonacci)
asset chat.js 839 bytes [emitted] (name: chat)
asset 129.js 741 bytes [emitted]
2021-06-28 18:30:25 +08:00
chunk (runtime: 9a81d90cfd0dfd13d748, main) 129.js 103 bytes [rendered]
2021-03-22 21:30:17 +08:00
> ./fibonacci ./example.js 70:30-51
2020-09-08 00:02:14 +08:00
> ./fibonacci ./fib-worker.js 2:29-50
./fibonacci.js 103 bytes [built] [code generated]
[exports: fibonacci]
2025-04-25 01:57:25 +08:00
[all exports used]
2021-03-22 21:30:17 +08:00
import() ./fibonacci ./example.js 70:30-51
2020-09-08 00:02:14 +08:00
import() ./fibonacci ./fib-worker.js 2:29-50
2021-06-28 18:30:25 +08:00
chunk (runtime: 1fad8bf8de78b0a77bfd) chat.js (chat) 527 bytes [entry] [rendered]
2021-03-22 21:30:17 +08:00
> ./example.js 25:19-31:1
2020-09-08 00:02:14 +08:00
./chat-worker.js + 1 modules 527 bytes [built] [code generated]
[no exports]
[no exports used]
2021-03-22 21:30:17 +08:00
new Worker() ./chat-worker.js ./example.js 25:19-31:1
2025-04-25 01:57:25 +08:00
chunk (runtime: 9a81d90cfd0dfd13d748) workers/fibonacci.js (fibonacci) 176 bytes (javascript) 1.88 KiB (runtime) [entry] [rendered]
2021-03-22 21:30:17 +08:00
> ./example.js 80:18-84:2
2025-04-25 01:57:25 +08:00
runtime modules 1.88 KiB 6 modules
2020-09-08 00:02:14 +08:00
./fib-worker.js 176 bytes [built] [code generated]
[no exports used]
2021-03-22 21:30:17 +08:00
new Worker() ./fib-worker.js ./example.js 80:18-84:2
2025-10-06 20:29:40 +08:00
chunk (runtime: main) main.js (main) 2.25 KiB (javascript) 5.42 KiB (runtime) [entry] [rendered]
2025-04-25 01:57:25 +08:00
> ./example.js main
2025-10-06 20:29:40 +08:00
runtime modules 5.42 KiB 7 modules
2025-04-25 01:57:25 +08:00
./example.js 2.25 KiB [built] [code generated]
[no exports used]
entry ./example.js main
2025-04-29 02:11:48 +08:00
webpack X.X.X compiled successfully
2020-09-08 00:02:14 +08:00
```
## Production mode
```
2025-10-06 20:29:40 +08:00
asset main.js 3.29 KiB [emitted] [minimized] (name: main)
2025-07-01 18:16:11 +08:00
asset workers/fibonacci.js 776 bytes [emitted] [minimized] (name: fibonacci)
2020-09-21 04:39:12 +08:00
asset chat.js 270 bytes [emitted] [minimized] (name: chat)
2025-04-25 01:57:25 +08:00
asset 129.js 159 bytes [emitted] [minimized]
2021-06-28 18:30:25 +08:00
chunk (runtime: 9a81d90cfd0dfd13d748, main) 129.js 103 bytes [rendered]
2020-09-08 00:02:14 +08:00
> ./fibonacci ./fib-worker.js 2:29-50
2025-04-25 01:57:25 +08:00
> ./fibonacci ./example.js 70:30-51
2020-09-08 00:02:14 +08:00
./fibonacci.js 103 bytes [built] [code generated]
[exports: fibonacci]
2025-04-25 01:57:25 +08:00
[all exports used]
2021-03-22 21:30:17 +08:00
import() ./fibonacci ./example.js 70:30-51
2020-09-08 00:02:14 +08:00
import() ./fibonacci ./fib-worker.js 2:29-50
2021-06-28 18:30:25 +08:00
chunk (runtime: 1fad8bf8de78b0a77bfd) chat.js (chat) 527 bytes [entry] [rendered]
2021-03-22 21:30:17 +08:00
> ./example.js 25:19-31:1
2020-09-08 00:02:14 +08:00
./chat-worker.js + 1 modules 527 bytes [built] [code generated]
[no exports]
[no exports used]
2021-03-22 21:30:17 +08:00
new Worker() ./chat-worker.js ./example.js 25:19-31:1
2025-04-25 01:57:25 +08:00
chunk (runtime: 9a81d90cfd0dfd13d748) workers/fibonacci.js (fibonacci) 176 bytes (javascript) 1.88 KiB (runtime) [entry] [rendered]
2021-03-22 21:30:17 +08:00
> ./example.js 80:18-84:2
2025-04-25 01:57:25 +08:00
runtime modules 1.88 KiB 6 modules
2020-09-08 00:02:14 +08:00
./fib-worker.js 176 bytes [built] [code generated]
[no exports used]
2021-03-22 21:30:17 +08:00
new Worker() ./fib-worker.js ./example.js 80:18-84:2
2025-10-06 20:29:40 +08:00
chunk (runtime: main) main.js (main) 2.25 KiB (javascript) 5.42 KiB (runtime) [entry] [rendered]
2025-04-25 01:57:25 +08:00
> ./example.js main
2025-10-06 20:29:40 +08:00
runtime modules 5.42 KiB 7 modules
2025-04-25 01:57:25 +08:00
./example.js 2.25 KiB [built] [code generated]
[no exports used]
entry ./example.js main
2025-04-29 02:11:48 +08:00
webpack X.X.X compiled successfully
2020-09-08 00:02:14 +08:00
```