【问题标题】:When run grunt I get SyntaxError: Unexpected token (当运行 grunt 我得到 SyntaxError: Unexpected token (
【发布时间】:2016-03-19 03:48:43
【问题描述】:

如标题中所述,当我运行 Grunt 时会发生这种情况,但我无法弄清楚我的代码有什么问题。我用JShint检查了一下,没有错误。

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/compiled.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
                }
            }
        },

        compass: {
            dist: {
                options: {
                    sassDir: 'development/css',
                    cssDir: 'dist/css',
                    environment: 'production',
                    outputStyle: 'compressed'
                }
            }
        },

        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', 'compass']
        }

    });

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

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

控制台输出:

正在加载“Gruntfile.js”任务...错误

SyntaxError: Unexpected token ( Warning: Task "default" not found. 使用 --force 继续。

由于警告而中止。

【问题讨论】:

    标签: javascript gruntjs


    【解决方案1】:

    第一个函数有语法错误,尝试将第一个函数更改为:

    (function(){
      "use strict";
    
     // Define your library strictly...
    })();
    

    【讨论】:

    • 你不能简单地在自己的线路上使用'use strict';
    猜你喜欢
    • 1970-01-01
    • 2019-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-15
    • 1970-01-01
    • 2021-11-03
    • 1970-01-01
    相关资源
    最近更新 更多