Created
November 24, 2021 15:28
-
-
Save dmnsgn/1b6b464a6c6aa2ed4d4c1d2a18042e02 to your computer and use it in GitHub Desktop.
Revisions
-
dmnsgn created this gist
Nov 24, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1 @@ console.log("foo"); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> </head> <body> <script src="dist/bundle.js" type="module"></script> </body> </html> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,9 @@ const myWorker = new Worker(new URL("worker.js", import.meta.url), { type: "classic", }); myWorker.onmessage = function (e) { console.log("Message received from worker", e.data); }; myWorker.postMessage([42]); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ { "name": "webpack-worker-type-classic", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "build": "npx webpack", "serve": "npx browser-sync" }, "keywords": [], "author": "Damien Seguin (https://github.com/dmnsgn)", "license": "MIT", "devDependencies": { "webpack": "^5.64.3", "webpack-cli": "^4.9.1" } } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ const path = require("path"); module.exports = { entry: "./index.js", mode: "production", optimization: { minimize: false, }, output: { path: path.resolve(__dirname, "dist"), filename: "bundle.js", clean: true, libraryTarget: "module", }, experiments: { outputModule: true }, }; This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ self.importScripts(new URL("./foo.js", import.meta.url)); onmessage = function (e) { console.log("Worker: Message received from main script"); const workerResult = "Result: " + e.data[0]; console.log("Worker: Posting message back to main script"); postMessage(workerResult); };