gpt4 book ai didi

angular - 对 'hammerjs' 的依赖。 CommonJS 或 AMD 依赖项可能导致优化救助

转载 作者:行者123 更新时间:2023-12-04 03:47:21 29 4
gpt4 key购买 nike

我正在使用 Angular CLI 11.0.2 开发一个 Angular 应用程序,我在我的应用程序中使用 hammerJS 来处理滑动事件。
当我编译应用程序时,我收到以下警告消息:

Warning: F:\Programs\GoodRiddles\git\angular\src\app\config\hammerjs.config.ts depends on 'hammerjs'. CommonJS or AMD dependencies can cause optimization bailouts.
For more info see: https://angular.io/guide/build#configuring-commonjs-dependencies
据我所知 here ,我应该用库的 ECMA 版本替换hammerJS。
我的问题是:
有没有合适的方法(而不是简单地隐藏消息)来修复它?我需要使用另一个库吗?
如果它可以提供帮助,这就是我使用它的方式:
import { Injectable } from '@angular/core';
import { HammerGestureConfig } from "@angular/platform-browser";
import * as hammer from "hammerjs";

@Injectable()
export class HammerConfig extends HammerGestureConfig {
overrides = <any>{
swipe: { direction: hammer.DIRECTION_HORIZONTAL },
pinch: { enable: false },
rotate: { enable: false }
};
}

最佳答案

在 angular.json 中将 Hammerjs 添加到 allowedCommonJsDependencies

"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"allowedCommonJsDependencies": [
"hammerjs" <== here
],...

关于angular - 对 'hammerjs' 的依赖。 CommonJS 或 AMD 依赖项可能导致优化救助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64948707/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com