Grunt UseminPrepare不生成配置

时间:2015-01-13 19:06:31

标签: javascript gruntjs

我正在尝试使用grunt-usemin来连接,缩小和删除项目中未使用的优化引用。我在build文件中设置了index.html块,如下所示:

的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实际上从未在concat中生成uglifygruntfile.js方法。相反,在尝试运行时

grunt.registerTask('newtask', ['useminPrepare', 'concat', 'uglify', 'usemin']);

我收到错误声明&#34;否&#34; concat&#34;发现的目标&#34;。

我的gruntfile.jsindex.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

2 个答案:

答案 0 :(得分:1)

像spamguy一样说: 发生此错误是因为您编写的html文件路径错误。

常见的是:

useminPrepare: {
   html: ['<%= yeoman.app %>/index.html'],
   options: {
      dest: '<%= yeoman.dist %>'
   }
}

请确保usemin可以通过html配置找到您的index.html文件。

答案 1 :(得分:0)

您在useminPrepare中的index.html引用缺少client/

useminPrepare: {
    html: 'client/index.html',
    options: {
        dest: '/dist'
    }
}

我与我正在研究的项目进行了比较,该项目似乎使用了相同的自动生成器。