【问题标题】:Grunt Concat cannot write to fileGrunt Concat 无法写入文件
【发布时间】:2013-03-20 04:12:50
【问题描述】:

刚刚在 Ubuntu 12.04 上安装了最新的 Grunt。这是我的 gruntfile:

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

    concat: {
        slides :  {
            src : ['src/top.html', 'src/bottom.html'],
            dest : ['build/index.html']
        }
    }
});

//enable plugins
grunt.loadNpmTasks('grunt-contrib');
grunt.registerTask('default', ['concat:slides']);
}

这很好地创建了 build/ 目录,但给了我以下输出:

运行“concat:slides”(concat) 任务警告:无法写入 “build/index.html”文件(错误代码:未定义)。使用 --force 来 继续。

我尝试在目录上运行 chmod 777,因为我认为它可能与权限有关,但这似乎并没有改变任何东西。

我怎样才能让 Grunt 写入 build/index.html?

【问题讨论】:

    标签: gruntjs


    【解决方案1】:

    想通了:

    //Does not work
    dest : ['build/index.html']
    

    作为字符串工作,但不是数组:

    //Works
    dest : 'build/index.html'
    

    【讨论】:

    • 我遇到了同样的问题,发现了一个类似的问题,并根据您的回答给了a detailed answer。所有的功劳都归你所有,非常感谢:)
    • 这个答案帮助我修复了另一个语法错误。确保使用“dest”而不是“dst”。
    • 我的是“desc”而不是“dest”。 (:
    【解决方案2】:

    我将 tasks/concat.js 更改为接受 dest 数组:

    // Write the destination file.
    // If f.dest is an array take the first element
    var dest  = ([].concat(f.dest))[0]
    grunt.file.write(dest, src);
    

    但后来我决定使用文件形式而不是 src/dest:

    files: { 'dest.js': ['a.js', 'b.js'] }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-04
      • 1970-01-01
      • 2013-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-29
      • 1970-01-01
      相关资源
      最近更新 更多