配置中的Grunt语法错误

时间:2016-11-25 01:52:05

标签: gruntjs

尝试在HTML文件中使用Javascript。所以我使用'replace'依赖来引用JS文件的宏。

由于在gruntfile.js配置中添加了replace函数,我收到了语法错误。

我确信我很遗憾。希望有人可以提供帮助吗?

module.exports = function (grunt) {

    var allJS = ['src/*.js'];

    // Project configuration.
    grunt.initConfig({

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

        jshint: {
            options: {
                scripturl: true
            },
            files: ['gruntfile.js', allJS]
        },
replace: {
				      normal: {
				        options: {
				          patterns: [
				            {
				              match: 'scriptmacro',
				              replacement: '<%= grunt.file.read("tmp/tmpmoatscript.js") %>'
				            },
				          ]
				        },
				        files: [
				          {
				            expand: true,
				            flatten: true,
				            src: ['src/index.html'],
				            dest: 'dist'
				          }
				        ]
				      },

        clean: {
            dist: ['dist']
        },

        uglify: {
            'main': {
                options: {
                    "banner": "",
                    enclose: {
                        window: "window",
                        document: "document"
                    },
                },

                files: {
                    'dist/min-moatscript.txt': 'src/moatscript.txt',
                }
            }
        }
		
    });

    // Load the plugin that provides the "uglify" task.
    grunt.loadNpmTasks('grunt-contrib-jshint');
    grunt.loadNpmTasks('grunt-contrib-uglify');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-replace');


    // Default task(s).
    grunt.registerTask('default', ['jshint', 'clean', 'uglify','replace',]);

};

提前致谢

1 个答案:

答案 0 :(得分:0)

initConfig的括号不匹配。

对于任何语法错误,您可以使用IDE /转到jshint.com查找。

&#13;
&#13;
module.exports = function(grunt) {

  var allJS = ['src/*.js'];

  // Project configuration.
  grunt.initConfig({

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

    jshint: {
      options: {
        scripturl: true
      },
      files: ['gruntfile.js', allJS]
    },
    replace: {
      normal: {
        options: {
          patterns: [{
            match: 'scriptmacro',
            replacement: '<%= grunt.file.read("tmp/tmpmoatscript.js") %>'
          }, ]
        },
        files: [{
          expand: true,
          flatten: true,
          src: ['src/index.html'],
          dest: 'dist'
        }]
      },

      clean: {
        dist: ['dist']
      },

      uglify: {
        'main': {
          options: {
            "banner": "",
            enclose: {
              window: "window",
              document: "document"
            },
          },

          files: {
            'dist/min-moatscript.txt': 'src/moatscript.txt',
          }
        }
      }

    }
  });

  // Load the plugin that provides the "uglify" task.
  grunt.loadNpmTasks('grunt-contrib-jshint');
  grunt.loadNpmTasks('grunt-contrib-uglify');
  grunt.loadNpmTasks('grunt-contrib-clean');
  grunt.loadNpmTasks('grunt-contrib-replace');

  // Default task(s).
  grunt.registerTask('default', ['jshint', 'clean', 'uglify', 'replace', ]);

};
&#13;
&#13;
&#13;

相关问题