【问题标题】:Grunt Syntax error in config配置中的 Grunt 语法错误
【发布时间】:2016-11-25 01:52:05
【问题描述】:

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

自从在 gruntfile.js 配置中添加替换功能后,我遇到了语法错误。

我确信我错过了这很简单。希望有人可以提供帮助?

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',]);

};

提前致谢

【问题讨论】:

    标签: gruntjs


    【解决方案1】:

    您的 initConfig 括号不匹配。

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-01
      • 2013-11-24
      • 2020-04-22
      • 1970-01-01
      • 1970-01-01
      • 2019-08-16
      相关资源
      最近更新 更多