angular - Angular2:Rollupjs捆绑与组件类中的相对路径

标签 angular gulp rollupjs

要支持i18n,如here所述,我必须支持aot,因此需要在组件中使用relativetemplateUrlstyleUrls,并设置moduleId: module.id
这非常适合我的dev构建,它不使用systemjs捆绑和加载文件(使用gulp构建)
编译类型脚本:`target:es5,module:commonjs'
在产品构建中,我使用rollup.js对树进行抖动和绑定。在这里,我必须完成以下步骤,因为rollup需要es2015模块,而浏览器(要在组件中设置module.id)需要common.js
编译类型脚本:target: es5, module: es2015
与rollup.js捆绑:format: iife
再次编译类型脚本:target: es5, module: commonjs, allowJs: true
执行此操作时,运行应用程序时出现以下错误:未能加载app.component.html
版本信息:
角度:2.2.1
类型脚本:2.0.10
汇总:0.36.3
有人知道是什么导致了这个问题吗?
非常感谢你的帮助

最佳答案

使用module.id时,必须在组件上为模块声明一个变量。即:

declare var module: any;
import { Component } from '@angular/core';

@Component({
  moduleId: module.id,
  selector: 'app',
  templateUrl: 'content.component.html'
})
export class ContentComponent {}

我希望这对你有用

关于angular - Angular2:Rollupjs捆绑与组件类中的相对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40761793/

相关文章:

angular - 将 Angular 版本 12 更新到 13 中的问题

javascript - gulp-concat 和 lazypipe 的这种组合在使用 gulp 4 时会导致错误吗?

encoding - 模块解析错误 : Module parse failed: iconv-lite

node.js - 直接将 Google Cloud Speech API 与 Angular 7 集成

html - 模板解析错误 : Unexpected closing tag "p"

webpack - 如何动态导入名称由带有 rollupjs 的参数定义的模块?

javascript - 如何将polyfills和外部库与Rollup JS捆绑在一起?

javascript - 应用程序汇总和树摇动

css - 使用纯 CSS 隐藏/显示时的 Angular 动画

gulp.watch 不获取新文件