Getting Error message “No ”concat“ targets found” when running grunt-usemin

自作多情 提交于 2020-01-14 14:39:21

问题


My grunt file is shown below:

module.exports = function(grunt) {

    // Project configuration.
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),
        uglify: {
            options: {
                banner: '/*! <%= pkg.name %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
            },
            build: {
                src: 'src/**/*.js',
                dest: 'dist/<%= pkg.name %>.min.js'
            }
        },
        watch: {
            js: {
                files: ['src/**/*.js'],
                options: {
                    livereload: '<%= connect.options.livereload %>'
                }
            },
            livereload: {
                options: {
                    livereload: '<%= connect.options.livereload %>'
                },
                files: [
                    'src/**/*.html',
                    'src/**/*.css',
                    'src/assets/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
                ]
            }
        },
        connect: {
            options: {
                port: 9000,
                livereload: 35729,
                hostname: 'localhost'
            },
            livereload: {
                options: {
                    open: true,
                    // base: [
                    //     '.tmp',
                    //     ''
                    // ]
                    middleware: function(connect) {
                        return [
                            connect.static('.tmp'),
                            connect().use(
                                '/bower_components',
                                connect.static('./bower_components')
                            ),
                            connect().use(
                                '/app/styles',
                                connect.static('./app/styles')
                            ),
                            connect.static('src')
                        ];
                    }
                }
            }
        },
        copy: {
            app: {
                cwd: 'src', // set working folder / root to copy
                src: '**/*.html', // copy all files and subfolders
                dest: 'dist/', // destination folder
                expand: true
            },
            assets: {
                cwd: 'src', // set working folder / root to copy
                src: 'assets/*', // copy all files and subfolders
                dest: 'dist/', // destination folder
                expand: true
            }
        },
        useminPrepare: {
            options: {
                dest: 'dist'
            },
            html: 'src/index.html'
        },

        usemin: {
            html: ['dist/index.html']
        }

    });

    // Load the plugin that provides the "uglify" task.
    // grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-connect');
    grunt.loadNpmTasks('grunt-contrib-watch');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-usemin');

    // Default task(s).
    grunt.registerTask('default', ['useminPrepare', 'copy', 'concat', 'uglify', 'usemin']);
    grunt.registerTask('serve', function(target) {
        grunt.task.run([
            'connect:livereload',
            'watch'
        ]);
    });

};

when i run grunt getting error message as "No "concat" targets found". I have been trying for 2 hours to solve this problem but no result pls help me to get the solution.


回答1:


Way too late, but just in case it is useful for somebody else: I believe useminprepare will auto-generate a concat configuration and feed it to the grunt task runner, so above responses are not quite accurate I would say.

I would try reviewing the build blocks in src/index.html and check that the paths point properly to the resources that useminPrepare will concatenate. I'm struggling now with a problem like this :S

Reference here: https://github.com/yeoman/grunt-usemin




回答2:


Use the following process to debug:

  • Run the sample project

  • Specify a temp storage location (temp or staging) directory

  • Before running usemin, make sure the temp or staging directory is not empty

  • If it is empty, run a grunt copy task which has the temp or staging directory set as the dest parameter

The main difference to be kept in mind, regarding directories and tasks, is that for useminPrepare, the directories needs to indicate the input, transient and output path needed to output the right configuration for the processors pipeline, whereas in the case of usemin it only reflects the output paths, as all the needed assets should have been output to the destination dir (either transformed or just copied).

References

  • grunt-usemin github repo: README

  • Concat, Uglify and Usemin Prepare



来源:https://stackoverflow.com/questions/31409150/getting-error-message-no-concat-targets-found-when-running-grunt-usemin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!