可以尝试在项目中添加以下代码以启用热模块替换(HMR):
ng add @angular-devkit/build-angular
"angularCompilerOptions": {
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableIvy": true
}
if (module.hot) {
module.hot.accept();
}
entry: [
'webpack-dev-server/client?http://localhost:4200',
'webpack/hot/dev-server',
'./src/main.ts'
],
这样,您应该能够在 Angular 12 项目中启用 HMR 并更新模块而无需重新加载页面。