【问题标题】:Strategy to use grunt-processhtml in development在开发中使用 grunt-processhtml 的策略
【发布时间】:2014-08-16 19:38:44
【问题描述】:

在开发环境中应该如何使用grunt-processhtml

例如,在index.html 中,我会在构建时为 angular 加载部分内容:

<!-- build:include:dist views/template-main.html -->
<script type="text/ng-template" id="views/template-main.html"> -->

</script>
<!-- /build -->

但我只希望在构建环境中发生这种情况,而不是在由 grunt serve 提供服务的开发环境 (app/) 环境中?

或者,举个更常见的例子,

<!-- @if NODE_ENV='production' -->
<script src=" production script "></script>
<!-- @endif -->
<!-- @if NODE_ENV='dev' -->
<script src=" sandbox script "></script>
<!-- @endif -->

我如何仅获取由grunt serve 提供的开发环境 (app/) 服务的沙盒脚本

我是否应该每次都执行grunt build,而不是grunt/node 提供app/ 的内容,以某种方式更改它以服务于开发版本(即dist/

或者我应该将这些grint-processhtml 指令(或任何预处理器)写在另一个文件中,例如pre.index.html 并将其构建到 index.html

否则,如果 grunt-processhtml 运行,它会删除指令,如果不是,浏览器显然会忽略 grunt-processhtml 指令并加载两个脚本。

(这是一个由 Yeoman 搭建的 AngularJS 项目,但这是一个通用的 grunt-processhtml 问题)

【问题讨论】:

    标签: gruntjs


    【解决方案1】:

    我想我误解了如何使用 grunt。

    我怀疑最好添加不同的构建目标,例如devproduction 等,而不仅仅是使用 app/dist

    这涉及设置不同的构建目标,设置要服务的不同目标。

    很好的解释:Have Grunt generate index.html for different setups

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-30
      • 1970-01-01
      • 2015-05-24
      • 2023-03-26
      • 2021-12-31
      相关资源
      最近更新 更多