【问题标题】:grunt-angular-templates write templates into a separate filegrunt-angular-templates 将模板写入单独的文件
【发布时间】:2015-10-13 13:47:40
【问题描述】:

我在我的应用程序中使用 ng-templates 和 usemin,我想将我的 angular 模板写入一个单独的文件,所以我在我的 .html 文件中创建了一个 usemin 块引用,如下所示:

<!-- build:js(.) scripts/templates.js -->
<!-- endbuild -->

我使用以下选项配置了 ngTemplates 任务:

ngtemplates: {
  dist: {
    cwd: '<%= yeoman.app %>',
    src: ['**/*.html'],
    dest: '.tmp/templateCache.js',
    options: {
      module: 'myTemplateModule',
      htmlmin: '<%= htmlmin.dist.options %>',
      usemin: 'scripts/templates.js'
    },
  }
}

但我刚刚发现 scripts/templates.js 文件没有创建,可能是因为 html 构建块是空的,所以模板没有被写入文件。

任何关于如何完成这项工作的建议都会很好。

【问题讨论】:

    标签: javascript templates build gruntjs grunt-usemin


    【解决方案1】:

    您按什么顺序调用任务?我发现 ngtemplateusemin 选项只有在您将其称为 after useminPrepare 任务时才有效,但 before 任何 usemin已调用生成的任务。 IE。你的任务应该是这样的:

    grunt.registerTask('build', [
      //preliminary tasks...
    
      'useminPrepare'
      //unrelated tasks...
      'ngtemplates'
      //unrelated tasks...
      'concat:generated' 
      //etc.
    
    ])
    

    这样做会生成模板文件,但usemin 不会将其插入到最终的 html 中,除非您在块中至少有一个文件。我建议将包含模板模块声明的文件放在块引用中,如下所示:

    <!-- build:js(.) scripts/templates.js -->
    <script src="path/to/module/templates.module.js"/>
    <!-- endbuild -->
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-03
      • 1970-01-01
      • 2015-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多