【发布时间】:2013-09-04 00:38:27
【问题描述】:
我正在使用 Yeoman 构建一个 Angular 应用程序。
有一部分 JavaScript 我只想在构建时包含在页面中(在 dist 文件夹中)。
有没有办法告诉在开发期间运行“grunt server”的 grunt 任务跳过模板的一部分,只将其包含在构建中?
【问题讨论】:
我正在使用 Yeoman 构建一个 Angular 应用程序。
有一部分 JavaScript 我只想在构建时包含在页面中(在 dist 文件夹中)。
有没有办法告诉在开发期间运行“grunt server”的 grunt 任务跳过模板的一部分,只将其包含在构建中?
【问题讨论】:
这听起来像是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 -->
您当然可以扭转这种局面,并拥有一个仅在服务器模式下才被删除的 sn-p。如果您将任务配置为在.tmp/ 中输出 HTML,则连接服务器将自动从那里提供文件。
然后您可以将processhtml 任务添加到您服务器的任务列表中,例如:
grunt.task.run([
'clean:server',
'concurrent:server',
'autoprefixer',
'processhtml:server',
'connect:livereload',
'open',
'watch'
]);
到 watch 部分,因此以后的更改也会触发文件的更新:
watch: {
html: {
files: ['<%= yeoman.app %>/*.html'],
tasks: ['processhtml:server']
}
}
【讨论】: