【发布时间】:2014-11-20 22:54:29
【问题描述】:
我正在使用 usemin 并且我通常喜欢它,但我真的不喜欢 usemin 覆盖我原来的 index.html 文件的事实。我的 Gruntfile 中有一个非常典型的设置:
useminPrepare: {
html: '<%= yeoman.app %>/index.html',
options: {
root: '<%= yeoman.root %>',
staging: '<%= yeoman.tmp %>',
dest: '<%= yeoman.dist %>',
flow: {
html: {
steps: {
js: ['concat', 'uglifyjs'],
css: ['cssmin']
},
post: {}
}
}
}
},
每当我使用 grunt 构建时,最终都会将所有内容转储到 dist 目录中。大多数其他需要进行“临时”修改的任务都会复制和修改 .tmp 目录中的文件。
usemin 与实际的 index.html 文件混为一谈。我特别不喜欢这样,因为它让 Github 认为每次我签入新代码时文件都发生了变化。
有没有办法告诉 usemin 像大多数其他 grunt 插件一样使用 .tmp 目录?
我确实指定了我的临时目录:
staging: '<%= yeoman.tmp %>'
但这似乎并不能防止 index.html 文件被覆盖。
谢谢。
更新(根据下面的评论)
这是 usemin 任务本身:
// Performs rewrites based on filerev and the useminPrepare configuration
usemin: {
html: ['<%= yeoman.dist %>/{,*/}*.html'],
css: ['<%= yeoman.dist %>/styles/{,*/}*.css'],
options: {
assetsDirs: ['<%= yeoman.dist %>','<%= yeoman.dist %>/images']
}
},
这是同时使用 useminPrepare 和 usemin 的 grunt 任务:
grunt.registerTask('build', [
'clean:dist',
'wiredep',
'useminPrepare',
'concurrent:dist',
'autoprefixer',
'concat',
'ngAnnotate',
'copy:dist',
'cdnify',
'cssmin',
'uglify',
'filerev',
'usemin',
'htmlmin',
'bridge:dist'
]);
【问题讨论】:
-
你能把包含 useminPrepare 的 grunt 任务粘贴到这里吗?
标签: gruntjs grunt-usemin