[英]react-app-rewired used to enable web workers fails to build
I'm using react-app-rewired
because I'm using web workers in my project.我正在使用
react-app-rewired
因为我在我的项目中使用了网络工作者。 So when I attempt to build everything goes fine but inside the build folder there is no index.html
or any js file.因此,当我尝试构建时一切正常,但在构建文件夹中没有
index.html
或任何 js 文件。 What am I doing wrong?我究竟做错了什么?
Here is my config-overrides
file:这是我的
config-overrides
文件:
module.exports = function override(config, env) {
config.module.rules.push({
test: /\.worker\.js$/,
use: { loader: 'worker-loader' }
});
config.output.globalObject = 'this';
return config;
};
I had the same issue and solved it by adding // eslint-disable-line no-restricted-globals to the worker file (myworker.worker.js).我遇到了同样的问题,并通过将// eslint-disable-line no-restricted-globals 添加到工作文件 (myworker.worker.js) 来解决它。
Example:例子:
self.addEventListener("message", getMessage); // eslint-disable-line no-restricted-globals
function getMessage(event) {
let message = event.data;
postMessage(message); //just relay back to main thread
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.