Yeoman& Grunt,如何仅包含构建

时间:2013-09-04 00:38:27

标签: gruntjs yeoman

我正在使用Yeoman构建一个Angular应用程序。

有一段JavaScript我只想在构建时包含在页面上(进入dist文件夹)。

有没有办法告诉在开发过程中运行'grunt服务器'的grunt任务跳过模板的一部分并且只将它包含在构建中?

1 个答案:

答案 0 :(得分:5)

这听起来像是grunt-processhtml的完美用例。

它允许您在HTML中放置某些指令。在您的情况下,remove指令可能是您正在寻找的:

<!-- build:remove -->
<p>This will be removed when any process is done</p>
<!-- /build -->

<!-- build:dist:remove -->
<p>But this one only when doing processhtml:dist</p>
<!-- /build -->

您当然可以转过来并拥有仅在服务器模式下删除的代码段。如果您将任务配置为在.tmp/中输出HTML,则连接服务器将自动从该处提供文件。

然后,您可以将processhtml任务添加到服务器的任务列表中,例如:

grunt.task.run([
  'clean:server',
  'concurrent:server',
  'autoprefixer',
  'processhtml:server',
  'connect:livereload',
  'open',
  'watch'
]);

以及稍后更改的监视部分也会触发文件更新:

watch: {
  html: {
    files: ['<%= yeoman.app %>/*.html'],
    tasks: ['processhtml:server']
  }
}