最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - When run grunt I get SyntaxError: Unexpected token ( - Stack Overflow

programmeradmin2浏览0评论

As mentioned in title, it happens when I run Grunt, and I can't figure out what is wrong with my code. I used JShint to check it, and there is no errors.

function () {
   'use strict';
}

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        concat: {
            options: {
                separator: 'rn'
            },
            dist: {
                src: ['development/js/**/*js'],
                dest: 'development/js/piled.js'
            }
        },

        uglify: {
            options: {
                banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */n'
            },
            dist: {
                files: {
                    'dist/js/main.min.js': ['<%= concat.dist.dest %>']
                }
            }
        },

        jshint: {
            files: ['development/js/**/*js'],
            options: {
                globals: {
                    jQuery: true,
                    console: true,
                    module: true
                }
            }
        },

        pass: {
            dist: {
                options: {
                    sassDir: 'development/css',
                    cssDir: 'dist/css',
                    environment: 'production',
                    outputStyle: 'pressed'
                }
            }
        },

        copy: {
            files: [
                {
                    cwd: 'development',  // set working folder / root to copy
                    src: '**/*html',           // copy all files and subfolders
                    dest: 'dist',    // destination folder
                    expand: true           // required when using cwd
                },
                {
                    cwd: 'development',  // set working folder / root to copy
                    src: 'img/*',           // copy all files and subfolders
                    dest: 'dist',    // destination folder
                    expand: true           // required when using cwd
                },
                {
                    cwd: 'development',  // set working folder / root to copy
                    src: 'fonts/*',           // copy all files and subfolders
                    dest: 'dist',    // destination folder
                    expand: true           // required when using cwd
                },
                {
                    cwd: 'path/to/files',  // set working folder / root to copy
                    src: '**/*',           // copy all files and subfolders
                    dest: 'dist',    // destination folder
                    expand: true           // required when using cwd
                }
            ]
        },

        watch: {
            files: ['<%= jshint.files %>', 'development/css/**/*.scss', 'development/**/*html'],
            tasks: ['concat', 'uglify', 'jshint', 'pass']
        }

    });

    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-pass');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-watch');

    grunt.registerTask('default', [
        'concat', 
        'uglify', 
        'jshint', 
        'pass',
        'copy'
    ]);
};

Console output:

Loading "Gruntfile.js" tasks...ERROR

SyntaxError: Unexpected token ( Warning: Task "default" not found. Use --force to continue.

Aborted due to warnings.

As mentioned in title, it happens when I run Grunt, and I can't figure out what is wrong with my code. I used JShint to check it, and there is no errors.

function () {
   'use strict';
}

module.exports = function(grunt) {
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        concat: {
            options: {
                separator: 'rn'
            },
            dist: {
                src: ['development/js/**/*js'],
                dest: 'development/js/piled.js'
            }
        },

        uglify: {
            options: {
                banner: '/*! <%= pkg.name %> <%= grunt.template.today("dd-mm-yyyy") %> */n'
            },
            dist: {
                files: {
                    'dist/js/main.min.js': ['<%= concat.dist.dest %>']
                }
            }
        },

        jshint: {
            files: ['development/js/**/*js'],
            options: {
                globals: {
                    jQuery: true,
                    console: true,
                    module: true
                }
            }
        },

        pass: {
            dist: {
                options: {
                    sassDir: 'development/css',
                    cssDir: 'dist/css',
                    environment: 'production',
                    outputStyle: 'pressed'
                }
            }
        },

        copy: {
            files: [
                {
                    cwd: 'development',  // set working folder / root to copy
                    src: '**/*html',           // copy all files and subfolders
                    dest: 'dist',    // destination folder
                    expand: true           // required when using cwd
                },
                {
                    cwd: 'development',  // set working folder / root to copy
                    src: 'img/*',           // copy all files and subfolders
                    dest: 'dist',    // destination folder
                    expand: true           // required when using cwd
                },
                {
                    cwd: 'development',  // set working folder / root to copy
                    src: 'fonts/*',           // copy all files and subfolders
                    dest: 'dist',    // destination folder
                    expand: true           // required when using cwd
                },
                {
                    cwd: 'path/to/files',  // set working folder / root to copy
                    src: '**/*',           // copy all files and subfolders
                    dest: 'dist',    // destination folder
                    expand: true           // required when using cwd
                }
            ]
        },

        watch: {
            files: ['<%= jshint.files %>', 'development/css/**/*.scss', 'development/**/*html'],
            tasks: ['concat', 'uglify', 'jshint', 'pass']
        }

    });

    grunt.loadNpmTasks('grunt-contrib-concat');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-pass');
    grunt.loadNpmTasks('grunt-contrib-copy');
    grunt.loadNpmTasks('grunt-contrib-watch');

    grunt.registerTask('default', [
        'concat', 
        'uglify', 
        'jshint', 
        'pass',
        'copy'
    ]);
};

Console output:

Loading "Gruntfile.js" tasks...ERROR

SyntaxError: Unexpected token ( Warning: Task "default" not found. Use --force to continue.

Aborted due to warnings.

Share Improve this question asked Dec 13, 2015 at 17:17 jazzgotjazzgot 4191 gold badge3 silver badges17 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 3

First function has a syntax error, try to change first function to:

(function(){
  "use strict";

 // Define your library strictly...
})();
发布评论

评论列表(0)

  1. 暂无评论