Grunt-contrib-copy task is failing when cwd option is specified - gruntjs

I have this grunt-copy setup:
copy: {
images: {
cwd: 'src/multiselect/lib/',
src: 'chosen.css',
dest: './built/css/',
flatten: true,
filter: 'isFile'
}
},
And when I run it, it always goes:
Running "copy:images" (copy) task
Warning: Unable to read "chosen.css" file (Error code: ENOENT). Use --force to continue.
Aborted due to warnings.
The weird thing is that if I run it with this config:
copy: {
images: {
src: 'src/multiselect/lib/chosen.css',
// src: 'chosen.css',
dest: './built/css/',
flatten: true,
filter: 'isFile'
}
},
It works every time. Does anyone have a clue as to why? It seems like the error occurs on this line of code:
grunt.file.copy(src, dest, copyOptions);
In grunt-contrib-copy task. Any help would be greatly appreciated.

You need to add expand:true
See http://gruntjs.com/configuring-tasks#building-the-files-object-dynamically

Related

I get an error when I run grunt jshint

I'm also going through Steven Foote's book Learning to Program and am currently on chapter 4, which uses Grunt. This post has a similar problem, but the problem is different (this person capitalized the "f" in Gruntfile.js).
I've seemed to have installed NPM and Node properly
npm#5.10.0 /usr/local/lib/node_modules/npm
andrews-macbook-air:Kittenbook Andrew$ node -v
v8.11.3
Here is my Gruntfile.js:
module.exports = function(grunt){
grunt.initConfig({
concat: {
release: {
src: ['js/values.js', 'js/prompt.js'],
dest: 'release/main.js'
}
},
copy: {
release: {
src: 'manifest.json',
dest: 'release/main.js'
}
},
jshint: {
files: ['js/values.js', 'js/prompt.js']
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTasks('default', ['jshint', 'concat' 'copy']);
In checking to see if I did it correctly I run grunt jshint in the command line, but I get back an error
andrews-macbook-air:Kittenbook Andrew$ grunt jshint
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected string
Warning: Task "jshint" not found. Use --force to continue.
Aborted due to warnings.
Any ideas on what is going on?

No "clean" targets found

Please help, I use Grunt and try to do grunt clean command, but I have
No "clean" targets found.
message as a result. How can I fix that?
copy: {
build: {
files: [{
expand: true,
src: [
"fonts/**/*.{woff, woff2}",
"img/**",
"js/**",
"*.html"
],
dest: "build"
}]
}
},
сlean: {
build: ["build"]
}
});
grunt.registerTask("serve", ["browserSync", "watch"]);
grunt.registerTask('default', ['copy']);
grunt.registerTask("build", [
"clean",
"copy",
"sass",
"postcss",
"csso",
"imagemin"
]);
};
The problem is that the character c in clean - in the grunt configuration literal - is not what it appears to be. It's U+0441 - a Cyrillic letter.
If you retype it and ensure that it is an ANSI c - or copy and paste the word clean from the registerTask call - your grunt configuration should behave as you are expecting it to.

grunt-contrib-copy error (Error code: ENOENT)

I searched internet and it looks only me had this problem with grunt-contrib-copy.
project
gruntfile.js
->app
->img
->pic1.png
->pic2.png
Result I expected:
project
gruntfile.js
->app
->dist
->img
->pic1.png
->pic2.png
->img
->pic1.png
->pic2.png
In another word, just copy files in /project/app/img to /project/app/dist/img.
Here is my copy config, which is NOT working:
copy: {
main: {
src: ['*.*'],
expend: true,
cwd: 'app/img/',
dest: 'app/dist/img/'
}
},
Here is error message:
Warning: Unable to read "download.png" file (Error code: ENOENT). Use --force to continue.
(download.png is the name of picture file)
How should I config the copy option? Thank you!
It looks like you have a typo, it should be expand instead of expend. So the cwd property is being ignored. Try the following config instead:
copy: {
main: {
src: ['**/*'],
expand: true,
cwd: 'app/img/',
dest: 'app/dist/img/'
}
},
The glob pattern *.* is probably not necessary as * will already match all files (unless you're specifically trying to match only files with a . in them.) Try using src: '*' to match all files within the single folder or src: '**/*' to match all files and folders within the cwd.

Contatenation with grunt-contrib-concat doesn't work

I use grunt-contrib-concat, but it doesn't appear to work.
All file are in the folder.
I used --verbose to see the details, but everything seems to be working correctly.
concat: {
options: {
// define a string to put between each file in the concatenated output
separator: ';'
},
dist: {
// the files to concatenate
src: [
//'assets/javascript/components/*.js',
'assets/javascript/components/jquery-ui-1.10.3.custom.js',
'assets/javascript/components/spectrum.js',
'assets/javascript/components/prefixfree.min.js',
'assets/javascript/src/jquery.menu_css3.js'
],
// the location of the resulting JS file
dest: 'assets/javascript/jquery.<%= pkg.name %>.min.js'
}
},
Running the tasks with --verbose:
Running "concat" task
Running "concat:dist" (concat) task
Verifying property concat.dist exists in config...OK
Files: assets/javascript/src/jquery.menu_css3.js -> assets/javascript/jquery.menu_css3.min.js
Options: separator=";", banner="", footer="", stripBanners=false, process=false
Reading assets/javascript/src/jquery.menu_css3.js...OK
Writing assets/javascript/jquery.menu_css3.min.js...OK
File "assets/javascript/jquery.menu_css3.min.js" created.
Running "uglify" task
Running "uglify:dist" (uglify) task
Verifying property uglify.dist exists in config...OK
Files: assets/javascript/jquery.menu_css3.min.js -> assets/javascript/jquery.menu_css3.min.js
Options: banner="", footer="", compress={"warnings":false}, mangle={}, beautify=false, report=false
Minifying with UglifyJS...Reading assets/javascript/jquery.menu_css3.min.js...OK
OK
Writing assets/javascript/jquery.menu_css3.min.js...OK
File "assets/javascript/jquery.menu_css3.min.js" created.

Grunt rename not working

My directory structure looks like this:
-src/
-----pages/
----------...
-----...
-build
My gruntfile contains the following task:
copy: {
all:{
dest:"<%= builddir %>/",
src: ["src/**/*.{yaml,yml,py,html,htm,json,css}"],
rename:function(d, s){return d.replace("src/","");}
}
},
builddir: "build/<%= pkg.name %>-<%= pkg.version %>-<%= date %>",
When I run the copy task, it copies all the selected files into the directory containing the package name, version and build date, as expected, but it copies the entire src directory. while I only want to copy the contents of the src directory, so I'm trying to remove src/' from dest using therename`property, which doesn't work for some reason.
I've only started using grunt today, so I might be makiing a rookie mistake here.
Hmm... I think all you need is the cwd (current working directory) option. Unless you in fact want to flatten the files into a single directory.
copy: {
all:{
expand: true,
dest:"<%= builddir %>/",
src: ["**/*.{yaml,yml,py,html,htm,json,css}"],
cwd: "src/"
}
}
You'll need to set the flatten option, which removes the directory structure.
copy: {
all:{
expand: true,
flatten: true,
dest:"<%= builddir %>/",
src: ["src/**/*.{yaml,yml,py,html,htm,json,css}"]
}
}

Resources