【问题标题】:Grunt not concatenating using grunt-contrib-concatGrunt 不使用 grunt-contrib-concat 连接
【发布时间】:2014-03-04 15:44:17
【问题描述】:

我的 Gruntfile.js 中有以下内容:

concat: {
  options: {
    // define a string to put between each file in the concatenated output
    separator: ';'
  },
  dist: {
    // the files to concatenate
    src: [
        'scripts/jquery.easing.1.3.js', 
        'scripts/SmoothScroll.js',
        'scripts/jquery.parallax-1.1.3.js', 
        'scripts/jquery.bxslider.js',
        'scripts/jquery.hoverdir.js', 
        'scripts/jquery.mixitup.js',
        'scripts/jquery.fitvids.js', 
        'scripts/respond.min.js',
        'scripts/theme.script.js', 
        'scripts/theme.settings.js'
    ],
    // the location of the resulting JS file
    dest: 'scripts.js'
  }
}

但是当我运行grunt concat 时,什么都没有发生。任务已加载并注册到:

grunt.loadNpmTasks('grunt-contrib-concat');
grunt.registerTask('concat', ['concat']);

我没有收到任何错误,但文件scripts.js 没有创建。知道我做错了什么吗?

【问题讨论】:

  • grunt.registerTask('concat', ['concat']); 的意义何在?使用相同的名字是灾难的根源。只需删除该行并重试grunt concat
  • 啊,这就是问题所在。我以为您必须注册所有任务,但我想这只是为了执行多项任务?
  • 好吧,如果你真的要创建一个新任务,你需要注册一个任务。在这里,您几乎没有使用 concat 任务(由插件定义)。无论如何,这解决了你的问题吗?
  • 是的。非常感谢。如果你把它写成答案,我会接受。
  • 我将其发布为答案。很高兴它有帮助!最好的。

标签: gruntjs grunt-contrib-concat


【解决方案1】:

grunt.registerTask('concat', ['concat']); 有什么意义?

使用相同的名字是灾难的根源。只需删除该行并重试grunt concat

【讨论】:

    【解决方案2】:

    在文件中添加 src 和 dest:

    concat: {
      options: {
        // define a string to put between each file in the concatenated output
        separator: ';'
      },
      dist: {
        files:[{
        // the files to concatenate
        src: [
            'scripts/jquery.easing.1.3.js', 
            'scripts/SmoothScroll.js',
            'scripts/jquery.parallax-1.1.3.js', 
            'scripts/jquery.bxslider.js',
            'scripts/jquery.hoverdir.js', 
            'scripts/jquery.mixitup.js',
            'scripts/jquery.fitvids.js', 
            'scripts/respond.min.js',
            'scripts/theme.script.js', 
            'scripts/theme.settings.js'
        ],
        // the location of the resulting JS file
        dest: 'scripts.js'
        }]
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2016-09-13
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 2015-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多