worker-plugin 介绍
特征
自动 编译Web Worker中加载的模块:
const worker = new Worker('./foo.js',{ type: 'module' });
^^^^^^^^^^
gets bundled using webpack
安装
npm install -D worker-plugin
webpack.con fig .js配置
+ const WorkerPlugin = require('worker-plugin');
module.exports = {
<...>
plugins: [
+ new WorkerPlugin()
]
<...>
}
使用
worker.js :?(our worker module)
// This is a module worker,so we can use imports (in the bro wser too!)
import { cal cula tePi } from './some-other-module';
addEventListener('message',event => {
postMessage(cal cula tePi(event.data));
});
main.js :?(our demo,on the main thread)
const piWorker = new Worker('./worker.js',{ type: 'module' });
piWorker.onmessage = event => {
console.log('pi: ' + event.data);
};
piWorker.postMessage(42);
网站地址 : https://npm.im/worker-plugin
GitHub: https://github.com/GoogleChromeLabs/worker-plugin
网站描述: 向Webpack 添加 本机Web Worker捆绑 支持
worker-plugin官方网站
官方网站: https://npm.im/worker-plugin
如果觉得 网站内容还不错,欢迎将 网站 推荐给程序员好友。