I'm new to gruntjs and struggling to understand why a simple copy file task is not working. Below is my code in Gruntfile.js.
module.exports = function (grunt) {
"use strict";
// Project configuration
grunt.initConfig({
pkg: grunt.file.readJSON("package.json"),
// copy other css files
copy: {
dist: {
files: {
//expand: true, // required when using cwd
//cwd: ['.'], // set working folder / root to copy
src: './wwwroot/lib/html5-reset/assets/css/reset.css', // copy all files and subfolders
dest: './wwwroot/css/' // destination folder
}
}
}
});
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.registerTask("copyCss", ["copy"]);
};
When I execute the task I'm getting the following error
Loading "Gruntfile.js" tasks...OK
+ copyCss
Running tasks: copy
Running "copy" task
Running "copy:dist" (copy) task
Verifying property copy.dist exists in config...OK
Files: ./wwwroot/lib/html5-reset/assets/css/reset.css -> src
Files: ./wwwroot/css/ -> dest
Options: encoding="utf8", processContent=false, processContentExclude=[], timestamp=false, mode=false
Copying ./wwwroot/lib/html5-reset/assets/css/reset.css -> src
Reading ./wwwroot/lib/html5-reset/assets/css/reset.css...OK
Writing src...ERROR
Warning: Unable to write "src" file (Error code: EISDIR). Used --force, continuing.
Done, but with warnings.
Process terminated with code 0.
Appreciated your help in pinpointing the issue.
The nodejs error
EISDIRis described as:Configure your
Gruntfile.jsas shown below instead.Gruntfile.js
Running the following command:
will copy the file named
reset.cssfrom thewwwroot/lib/html5-reset/assets/css/directory to thewwwroot/css/directory.Example Before:
Example After:
Edit: Creating a custom task instead of using grunt-contrib-copy
If you are only wanting to copy one file then using
grunt-contrib-copyseems somewhat unnecessary. Consider creating a custom Task instead. For instance:Gruntfile.js
The aforementioned custom task utilizes grunt's build-in
grunt.file.copymethod.You may also want to consider adding some error handling to that custom Task too. For instance, you may want to utilize grunt's built-in
grunt.file.existsmethod to check whether thereset.cssfile exists before proceeding to copy it.