文件夹结构是这样的
app
|
+- html
| +- index.html
+- assets
| +- js
| +- foo.js
| +- bar.js
+- dist
我的Gruntfile.js是
module.exports = function (grunt) {
grunt.initConfig({
config: {
app: 'app',
dist: 'dist'
},
useminPrepare: {
html: 'html/index.html',
options: {
root: '<%= config.app %>',
dest: '<%= config.dist %>'
}
},
usemin: {
html: ['<%= config.dist %>/html/index.html'],
js: '<%= config.dist %>/assets/js/*.js'
}
});
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-rev');
grunt.loadNpmTasks('grunt-usemin');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-cssmin');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.registerTask('build', [
'useminPrepare',
'concat:generated',
'cssmin:generated',
'uglify:generated',
'usemin'
]);
};
在html/index . html <!-- build:js /assets/js/optimized.js -->
<script src="/assets/js/foo.js"></script>
<script src="/assets/js/bar.js"></script>
<!-- endbuild -->
当我执行"grunt build"命令时,它显示"无法处理任务"。必需的配置属性concat。生成丢失"错误。原因是什么呢?
如果你的Gruntfile.js在根位置,那么你在useminPrepare任务中有错误的html路径。我不确定useminPrepare是否理解"root"选项。试试这个:
useminPrepare: {
html: 'app/html/index.html',
options: {
dest: '<%= config.dist %>'
}
}