我正在使用Angular 6应用,并且正在尝试使用网络工作人员Worker
(通过ngx-web-worker
)执行一些复杂且耗费CPU的操作。我有以下服务:
import { MY_SCRIPT } from './my-script.script';
import { WebWorkerService } from 'ngx-web-worker';
@Injectable({
providedIn: 'root',
})
export class MyService {
constructor(private webworkerService: WebWorkerService) {
this.webworkerService.run(MY_SCRIPT).then((data) => {
console.log(data);
}, (error) => {
console.error(error);
});
}
}
其中my-script.script.ts
包含以下内容:
import { HelperClass } from './helper.class';
export const MY_SCRIPT = () => {
const helperClass: HelperClass = new HelperClass();
helperClass.doExpensiveComputation();
};
和helper.class.ts
包含以下内容:
export class HelperClass {
doExpensiveComputation() {
// do some complex and expensive computation
}
}
类HelperClass
没有导入任何Angular模块中。该应用程序运行良好,但是在运行时出现以下错误消息:
Uncaught ReferenceError: _helper_class__WEBPACK_IMPORTED_MODULE_0__ is not defined
如何为webpack提供所需的信息?