我正在尝试使用grunt-usemin
来连接、缩小和删除项目中未使用的优化引用。我已在 index.html
文件中设置了 build
block ,如下所示:
Index.html
<!-- build:js js/optimized.js-->
<script src="app/app.js"></script>
<script src="app/config.js"></script>
<script src="app/config.exceptionHandler.js"></script>
<script src="app/config.route.js"></script>
<script src="app/common/common.js"></script>
<script src="app/common/bootstrap/bootstrap.dialog.js"></script>
<script src="app/controller1/controller1.js"></script>
<script src="app/services/service.js"></script>
<!-- endbuild -->
我的gruntfile.js
看起来像:
"use strict";
module.exports = function (grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
useminPrepare: {
html: 'index.html',
options: {
dest: '/dist'
}
},
usemin: {
options: {
dirs: ['dist/index.html']
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-usemin');
grunt.registerTask('testtask', ['useminPrepare', 'concat', 'uglify', 'usemin']);
};
但是,usemin
实际上从未在我的 gruntfile.js
中生成 concat
或 uglify
方法。相反,当尝试运行
grunt.registerTask('newtask', ['useminPrepare', 'concat', 'uglify', 'usemin']);
我收到一条错误消息,指出“未找到“concat”目标”。
我的gruntfile.js
和index.html
都在根目录中。我在这里做错了什么吗?
编辑:使用 --verbose
运行
Running tasks: useminPrepare
Running "useminPrepare" task
Running "useminPrepare:html" (useminPrepare) task
Verifying property useminPrepare.html exists in config...OK
Files: [no src] -> html
Options: dest="/dist"
Going through to update the config
Looking for build script HTML comment blocks
Configuration is now:
concat:
undefined
uglify:
undefined
cssmin:
undefined
最佳答案
就像垃圾邮件发送者所说: 出现这个错误是因为你的html文件路径写错了。
常见的是:
useminPrepare: {
html: ['<%= yeoman.app %>/index.html'],
options: {
dest: '<%= yeoman.dist %>'
}
}
请确保usemin可以通过您的html配置找到您的index.html文件。
关于javascript - Grunt UseminPrepare 不生成配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27929650/