git clone git@gist.github.com:661932b006d32769238cfea71333ce48.git worker-plugin-69
cd worker-plugin-69
npm i
npm start
# or
npm run dev
-
-
Save developit/661932b006d32769238cfea71333ce48 to your computer and use it in GitHub Desktop.
This file contains 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 characters
node_modules | |
package-lock.json | |
dist |
This file contains 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 characters
console.log('hello from main thread'); | |
const worker = new Worker('./worker.js', {type:"module"}); | |
worker.postMessage("hello"); | |
worker.onmessage = e => { | |
console.log('main thread got message: ', e.data); | |
}; |
This file contains 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 characters
{ | |
"name": "worker-plugin-69", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"start": "npm run build && serve dist", | |
"dev": "webpack-dev-server", | |
"build": "webpack -p" | |
}, | |
"keywords": [], | |
"author": "", | |
"license": "ISC", | |
"devDependencies": { | |
"html-webpack-plugin": "^4.3.0", | |
"serve": "^11.3.0", | |
"webpack": "^4.43.0", | |
"webpack-cli": "^3.3.11", | |
"webpack-dev-server": "^3.10.3", | |
"worker-plugin": "^4.0.3" | |
} | |
} |
This file contains 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 characters
var path = require('path'); | |
const WorkerPlugin = require('worker-plugin'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
module.exports = { | |
mode: 'development', | |
plugins: [ | |
new WorkerPlugin(), | |
new HtmlWebpackPlugin() | |
], | |
entry: './index.js', | |
//target: 'node', | |
output: { | |
path: path.resolve('dist'), | |
filename: 'bundle.js' | |
}, | |
resolve: { | |
extensions: ['.jsx','.js'] | |
} | |
} |
This file contains 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 characters
import path from 'path'; | |
// just to show we're getting bundled | |
console.log(path.join('foo', 'bar')); | |
addEventListener('message', e => { | |
console.log('worker received message: ', e.data); | |
}); | |
console.log('hello from worker!'); | |
postMessage('a message from the worker'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment