0
module.exports = function(grunt){
    'use strict';
    require('load-grunt-tasks')(grunt);

    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        //Lint JavaScript (validate JS)
        jshint: {
            all: {
                options: {
                    force: true
                },
                src: ['Gruntfile.js', 'source/js/*.js', 'source/views/js/*.js']
            }
        },
        // Lint CSS (validate CSS)
        csslint: {`enter code here`
            lax: {
                options: {
                    force: true
                },
                src: ['source/css/*.css', 'source/views/css/*.css']
            }
        },
        //Clean and New folder for optimized code
        clean: {
            dev: {
                src: ['dest/'],
            },
        },
        mkdir: {
            dev: {
                options: {
                    create: ['dest/']
                },
            },
        },
        //Copy thee files in 'dest' folder
        copy: {
            main: {
                files: []
                    {expand: true, cwd: 'source/', src: ['**'], dest: 'dest/'}
                ],
            },
        },
        //JS Minification
        uglify: {
            my_target: {
                files: [{
                    expand: true,
                    cwd: 'dest/js',
                    src: ['*.js'],
                    dest: 'dest/js'
                },{
                    expand: true,
                    cwd: 'dest/views/js',
                    src: ['*.js'],
                    dest: 'dest/views/js'
                }]
            }
        },
        //CSS Minification
        cssmin: {
            target: {
                files: [{
                    expand: true,
                    cwd: 'dist/css',
                    src: ['*.css'],
                    dest: 'dist/css',
                    ext: '.css'
                },{
                    expand: true,
                    cwd: 'dist/views/css',
                    src: ['*.css'],
                    dest: 'dist/views/css',
                    ext: '.css'
                }]
            }
        },
        // resize images from pizza
        responsive_images: {
            dev: {
                options: {
                    engine: 'im',
                    sizes: [{
                        width: 77,
                        quality: 60
                    },{
                        width: 116,
                        quality: 60
                    },{
                        width: 232,
                        quality: 60
                    },{
                        width: 720,
                        quality: 60
                    }]
                },
                files: [{
                    expand: true,
                    src: ['**.{gif,jpg,png}'],
                    cwd: 'dest/views/images/',
                    dest: 'dest/views/images/'
                }]
            }
        }
    });
    grunt.registerTask('default', [
        'jshint',
        'csslint',
        'clean',
        'mkdir',
        'copy',
        'uglify',
        'cssmin',
        'responsive_images'
    ]);
};

在命令提示符中运行 grunt 会出现错误:

正在加载“gruntfile.js”任务...错误>> SyntaxError:意外令牌警告:找不到任务“默认”。使用 --force 继续。

我不知道我哪里出错了。感谢任何帮助!

4

1 回答 1

1

您的 gruntfile 中有错字。

改变

// ... config before
copy: {
    main: {
        files: []
            {expand: true, cwd: 'source/', src: ['**'], dest: 'dest/'}
        ],
    },
},
// ... config after

至:

// ... config before
copy: {
    main: {
        files: [ //removed array close
            {expand: true, cwd: 'source/', src: ['**'], dest: 'dest/'}
        ]
    }
},
// ... config after
于 2016-11-23T06:55:28.990 回答