Grunt Concat cannot write to file

耗尽温柔 提交于 2020-01-03 06:44:09

问题


Just installed latest Grunt on Ubuntu 12.04. Here is my 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']);
}

This creates the build/ directory fine, but gives me the output of:

Running "concat:slides" (concat) task Warning: Unable to write "build/index.html" file (Error code: undefined). Use --force to continue.

I tried running chmod 777 on the directory, as I thought it might have something to do with permissions, but that didn't seem to change anything.

How can I make it so Grunt will write to build/index.html?


回答1:


Figured it out:

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

Works as a string, but not an array:

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



回答2:


I changed tasks/concat.js to accept arrays for 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);

but later I decided to use the files form instead of src/dest:

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


来源:https://stackoverflow.com/questions/15515192/grunt-concat-cannot-write-to-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!