Angular13升级后的Mixins/Webpack问题
创始人
2024-10-22 00:00:41
0
  1. 将 Mixin 的实现替换为继承

在 ng-packagr 的 v13 中,mixin 的实现方式发生了变化,因此你可能需要修改你的代码。在混入(mixin)中,一些 @Input()@Output() 被转换为 Angular settergetter。在 Angular v13 中,如果某个组件继承了混合类型,还需要在该组件中手动实现与指令的绑定。因此,为了避免这些问题,建议在升级到 Angular 13 时,将mixin的实现方式替换为继承。

以下是一个示例代码,展示如何使用类继承来代替 mixins。

import { Component, Input } from '@angular/core';
import { SimpleMixin } from './mixin';

class BaseComponent extends SimpleMixin {
  @Input() defaultValue: string = '';
}

@Component({
  selector: 'app-component',
  template: `

{{ hello() }}

`, }) export class AppComponent extends BaseComponent { hello() { return `Hello ${this.name || this.defaultValue}!`; } }
  1. 在 webpack 配置中添加引用 tsconfig.json 的选项。

如果你遇到了升级到 Angular 13 后构建过程中,遇到了类似于下面这种的 TypeScript 编译错误:

ERROR in ./src/app/app.module.ts 25:100-110
TS2769: No overload matches this call.
  Overload 1 of 3, '(options: CompilerOptions | undefined, fileNames?: readonly string[] | undefined): Program', gave the following error.
    Argument of type 'Configuration' is not assignable to parameter of type 'CompilerOptions'.
  Overload 2 of 3, '(jsonObject: any, basePath: string, existingOptions?: CompilerOptions | undefined, configFilePath?: string | undefined, watchOptions?: WatchOptions | undefined): P...', gave the following error.
    Argument of type 'Configuration' is not assignable to parameter of type 'TsConfigSourceFile | CompilerOptions'.

那么这可能是由于 TypeScript 引用了不同的tsconfig.json造成的。解决办法是在 webpack 配置中添加引用 tsconfig.json 的选项。

angular.json 文件中的 build 配置中添加以下内容:

相关内容

热门资讯

透视模块!hhpoker是真的... 透视模块!hhpoker是真的吗(HHpoker机器人)本来是真的有辅助技巧(哔哩哔哩)在进入hhp...
透视诀窍!epoker有透视吗... 透视诀窍!epoker有透视吗(透视)pokemmo修改器手机版(辅助)真是真的是有教程(哔哩哔哩)...
透视学习!wepokerplu... 透视学习!wepokerplus到底是挂了吗(WePoKer价格)好像是真的有辅助脚本(哔哩哔哩)1...
透视教程书!德州透视竞技联盟(... 透视教程书!德州透视竞技联盟(透视)pokerworld软件(辅助)真是一直总是有app(哔哩哔哩)...
透视模板!wepoker有脚本... 透视模板!wepoker有脚本吗(WePoKer私人局)真是存在有辅助攻略(哔哩哔哩)一、wepok...
透视技法!pokeplus脚本... 透视技法!pokeplus脚本(HHpoker控制牌)确实是真的有辅助攻略(哔哩哔哩)1、每一步都需...
透视教程书!智星德州插件(透视... 透视教程书!智星德州插件(透视)智星菠萝辅助(辅助)其实是真的有方法(哔哩哔哩)1、许多玩家不知道智...
透视项目!智星德州插件最新版本... 透视项目!智星德州插件最新版本更新内容详解(透视)德州机器人代打脚本(辅助)其实真的是有攻略(哔哩哔...
透视窍门!wepoker私人局... 透视窍门!wepoker私人局辅助(WePoKer轻量版)竟然有辅助脚本(哔哩哔哩)1、很好的工具软...
透视课程!aapoker透视怎... 透视课程!aapoker透视怎么用(WePoKer透视挂)真是是真的有辅助脚本(哔哩哔哩)aapok...