您的问题与 usemin 有关,请参阅此处的文档:https ://github.com/yeoman/grunt-usemin
只需将 index.html 中的注释替换为:
<!-- build:js(./) /dashboard/scripts/vendor.js -->
意思是:
<!-- build:PATH_WHERE_TO_FIND_FILES DESTINATION_PATH -->
用 ngAnnotate 替换 ngmin:
修改你的 Gruntfile:
代替:
// ngmin tries to make the code safe for minification automatically by
// using the Angular long form for dependency injection. It doesn't work on
// things like resolve or inject so those have to be done manually.
ngmin: {
dist: {
files: [{
expand: true,
cwd: '.tmp/concat/scripts',
src: '*.js',
dest: '.tmp/concat/scripts'
}]
}
},
经过
ngAnnotate: {
options: {
singleQuotes: true
},
dist: {
files: [{
expand: true,
cwd: '.tmp/concat/scripts',
src: '*.js',
dest: '.tmp/concat/scripts'
}]
}
},
并替换:
grunt.registerTask('build', [
'clean:dist',
'wiredep',
'useminPrepare',
'concurrent:dist',
'autoprefixer',
'concat',
'ngmin',
'copy:dist',
'cdnify',
'cssmin',
'uglify',
'filerev',
'usemin',
'htmlmin'
]);
经过:
grunt.registerTask('build', [
'clean:dist',
'wiredep',
'useminPrepare',
'concurrent:dist',
'autoprefixer',
'concat',
'ngAnnotate',
'copy:dist',
'cdnify',
'cssmin',
'uglify',
'filerev',
'usemin',
'htmlmin'
]);
运行这两个命令来修改你的 package.json: 1. npm uninstall grunt-ngmin --save 2. npm install grunt-ng-annotate --save