我想在“Antd Pro”项目中使用网络工作者。我尝试了在网上找到的不同方法,但没有一个有效。
“Antd Pro”由内部使用 Webpack 的 Umijs 框架驱动。为此,我发现的唯一方法是使用 Chain Webpack。
顺便说一句,我在这个项目中使用了 Typescript。
这是配置:
config.module
.rule('worker-loader')
.enforce('pre')
.test(/\.worker\.[t|j]s$/)
.use('worker-loader')
.loader('worker-loader')
.options({
inline: 'no-fallback',
});
我得到了这个错误:
ERROR Failed to compile with 1 errors 10:39:36 PM
error in ./src/pages/exp/Camera/MediaStreamAdapter.worker.ts
Module build failed (from ./node_modules/worker-loader/dist/cjs.js):
TypeError: The 'compilation' argument must be an instance of Compilation
at getCompilationHooks (C:\Users\moujar\Documents\ecomrepo\i.sale.desktop\node_modules\webpack\lib\javascript\JavascriptModulesPlugin.js:119:10)
at C:\Users\moujar\Documents\ecomrepo\i.sale.desktop\node_modules\webpack\lib\javascript\ArrayPushCallbackChunkFormatPlugin.js:29:19
at SyncHook.eval (eval at create (C:\Users\moujar\Documents\ecomrepo\i.sale.desktop\node_modules\tapable\lib\HookCodeFactory.js:19:10), <anonymous>:9:1)
at SyncHook.lazyCompileHook (C:\Users\moujar\Documents\ecomrepo\i.sale.desktop\node_modules\tapable\lib\Hook.js:154:20)
at Compiler.newCompilation (C:\Users\moujar\Documents\ecomrepo\i.sale.desktop\node_modules\@umijs\bundler-webpack\node_modules\webpack\lib\Compiler.js:630:30)
at C:\Users\moujar\Documents\ecomrepo\i.sale.desktop\node_modules\@umijs\bundler-webpack\node_modules\webpack\lib\Compiler.js:667:29
at AsyncSeriesHook.eval [as callAsync] (eval at create (C:\Users\moujar\Documents\ecomrepo\i.sale.desktop\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:6:1)
at AsyncSeriesHook.lazyCompileHook (C:\Users\moujar\Documents\ecomrepo\i.sale.desktop\node_modules\tapable\lib\Hook.js:154:20)
at Compiler.compile (C:\Users\moujar\Documents\ecomrepo\i.sale.desktop\node_modules\@umijs\bundler-webpack\node_modules\webpack\lib\Compiler.js:662:28)
at Compiler.runAsChild (C:\Users\moujar\Documents\ecomrepo\i.sale.desktop\node_modules\@umijs\bundler-webpack\node_modules\webpack\lib\Compiler.js:328:8)
at runAsChild (C:\Users\moujar\Documents\ecomrepo\i.sale.desktop\node_modules\worker-loader\dist\supportWebpack4.js:11:26)
at Object.pitch (C:\Users\moujar\Documents\ecomrepo\i.sale.desktop\node_modules\worker-loader\dist\index.js:97:34)