我想在一个vue项目用web worker 处理高并发的socket,想在里面用ES6模块所以配置了worker-loader,结果编译后经常拿不到worker脚本Uncaught SyntaxError: Unexpected token '<'
main.js :
import Worker from './workers/socket.worker.js'
Vue.prototype.$priceWk = new Worker()
socket.worker.js :
onmessage = (event) => {
if (!event) return;
const { type, payload } = event.data;
console.log( type, payload )
}
webpack.config.js :
{
test: /.worker.(c|m)?js$/i,
loader: 'worker-loader',
options: {
filename: (pathData) => {
if (/.worker.(c|m)?js$/i.test(pathData.chunk.entryModule.resource)) {
return '[name].js'
}
return '[name].worker.js'
},
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…