【发布时间】:2018-10-24 09:02:45
【问题描述】:
当我尝试构建生产版本时,我在 Ionic 应用程序中遇到了 ngx-translate 问题。
在开发过程中,翻译工作正常
ionic serve
和
ionic cordova build android
但如果我尝试使用
进行生产构建ionic cordova build android --prod --release
或用于 PWA
ionic build --prod
我收到一些错误,例如
[17:47:15] typescript error
The pipe 'translate' could not be found ( ... )
版本:
- ngx 翻译:8.0.0
- 离子:3.9.2
- 角度:5.2.10
我检查过:https://github.com/ngx-translate/core/tree/v8.0.0,但找不到我做错了什么。
在 app.module 中:
// https://github.com/ngx-translate/core#1-import-the-translatemodule
// AoT requires an exported function for factories
export function createTranslateLoader(http: Http) {
return new TranslateHttpLoader( http, './assets/i18n/', '.json' );
}
@NgModule( {
...
imports: [
...
TranslateModule.forRoot( {
loader: {
provide: TranslateLoader,
useFactory: (createTranslateLoader),
deps: [ Http ]
}
}
),
...
在我的一个产生此错误的页面中:
import { TranslateModule, TranslateService, TranslatePipe } from '@ngx-translate/core';
@NgModule({
imports: [
TranslateModule
],
exports: [
TranslateModule
]
})
export class ContactPage { ... }
通过 SO 搜索主要产生了在页面中导入和导出 TranslateModule 以及导入 TranslatePipe 的提示,但是这两个更改都没有解决我的问题。如何配置翻译模块以使其在生产版本中工作?
【问题讨论】:
标签: ionic-framework ngx-translate