我在angular.json JS依赖部分添加了几个模块,如下所示:
"allowedCommonJsDependencies": ["angular2-wizard", "hammerjs", "moment-timezone"]
但我刚刚升级了所有的东西,我又收到了一个关于我创建的管道的警告:
[webpack-dev-server] WARNING
/Users/mysite/client/src/app/pipes/time-zone.pipe.ts depends on 'moment'. CommonJS or AMD dependencies can cause optimization bailouts.
我尝试将.ts文件名添加到下面的列表中,但仍然收到警告。
"allowedCommonJsDependencies": ["angular2-wizard", "hammerjs", "moment-timezone", "time-zone"]
我还尝试过:“timezone.pipe.ts”和“TimeZonePipe”,这是类的名称,但似乎都没有删除警告。
我该怎么解决这个问题?
import {
Pipe,
PipeTransform
} from '@angular/core';
import * as moment from 'moment';
@Pipe({
name: 'timeZone'
})
export class TimeZonePipe implements PipeTransform {
transform(dateUtc: Date, timeZone: string, momentFormat: string, convertJustTimeZone = false): string {
const tempDateUtc = moment(dateUtc).utc(true);
tempDateUtc.tz(timeZone, convertJustTimeZone);
return tempDateUtc.format(momentFormat);
}
}