给出以下源树:
dev
?- psd
?- psd.psd
?- png.png
?- css
?- css.css
?- image
?- 1.jpg
?- 2.png
?html.html
Run Code Online (Sandbox Code Playgroud)
如何复制到pub目录,忽略psd文件夹,如下所示?
pub
?- css
?- css.css
?- image
?- 1.jpg
?- 2.png
?html.html
Run Code Online (Sandbox Code Playgroud)
我尝试了以下方法:
{
expand: true,
src: ['dev/**/*', '!dev/psd/**/*'],
dest: 'pub/'
}
Run Code Online (Sandbox Code Playgroud)
但这会导致一个空psd目录
我想要的内容复制/pckg到/dist与grunt.js.这是结构:
|-- folder1
| |
| |-- folder2
| |
| |-- pckg
| |
| |--myfolder
| | |
| | |-- myfiles
| |
| |--myfiles
|
|
|-- dist
|
|--myfolder
| |
| |-- myfiles
|
|--myfiles
Run Code Online (Sandbox Code Playgroud)
这是我的 Gruntfile.js
module.exports = function (grunt) {
// Package configuration
grunt.initConfig({
// Metadata
pkg: grunt.file.readJSON('package.json'),
//Copy files
copy: {
main: {
expand: true,
src: 'folder1/folder2/pckg/**',
dest: 'dest/'
}
}
});
// Load the plugin that …Run Code Online (Sandbox Code Playgroud) 第一次使用此任务,我正在尝试实现的目标如下:
从复制所有目录/文件src/js/bower_components/*到build/assets/js/vendor/
我尝试过使用cwd属性但是当我使用它时它根本不起作用..我已经将它设置为:src/js/bower_components/
来自src
.
??? Gruntfile
??? src
??? js
??? bower_components
??? jquery
Run Code Online (Sandbox Code Playgroud)
我目前得到:
.
??? Gruntfile
??? build
??? assets
??? js
??? vendor
src
??? js
??? bower_components
??? jquery
Run Code Online (Sandbox Code Playgroud)
我想要什么
.
??? Gruntfile
??? build
??? assets
??? js
??? vendor
???jquery
Run Code Online (Sandbox Code Playgroud)
这是我目前的咕噜声任务
copy: {
main: {
src: 'src/js/bower_components/*',
dest: 'build/assets/js/vendor/',
expand: true,
}
},
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助
我有一个目录结构如下:
source/
libraries/
d3.js
lodash.js
//etc
Run Code Online (Sandbox Code Playgroud)
我有如下的grunt-copy设置:
copy: {
main: {
files: [
{
src: ["source/libraries/*.js"],
dest: "build/",
flatten: true
}
Run Code Online (Sandbox Code Playgroud)
我希望它能将输出变成构建,这样我就可以了
build/
d3.js
//etc
Run Code Online (Sandbox Code Playgroud)
相反,我在构建中获得了原始目录结构的复制:
build/
source/
libraries/
d3.js
//etc
Run Code Online (Sandbox Code Playgroud)
是什么赋予了?我没有正确使用扁平?
只是想知道是否可以设置'复制'任务来做选择性副本?比如,如果一个任务想要将某些文件作为目标进行复制,而另一个任务可能想要定位其他任务.
我看到在所有的例子中都使用了'main',但我找不到引用是否可以使用其他名称,或者使用grunt-multi-dest之外的其他方法来实现这一点
copy: {
main: {
files: [
{
cwd: 'src_static/img/',
src: ['**'],
dest: '../mainProject/assets/img/'
}
],
onlyIcons: {
files: [
{
cwd: 'src_static/img/icons/',
src: ['**'],
dest: '../mainProject/assets/img/icons/'
}
],
}
}
grunt.registerTask('copy-all', ['copy']);
grunt.registerTask('copy-icons', ['copy:onlyIcons']);Run Code Online (Sandbox Code Playgroud)
虽然已经关闭,但有人要求我在grunt-contrib-copy网站上引用我发布的问题:https://github.com/gruntjs/grunt-contrib-copy/issues/230#issuecomment-96467261
谢谢.-Keith
我有这个grunt-copy设置:
copy: {
images: {
cwd: 'src/multiselect/lib/',
src: 'chosen.css',
dest: './built/css/',
flatten: true,
filter: 'isFile'
}
},
Run Code Online (Sandbox Code Playgroud)
当我运行它时,它总是会:
Running "copy:images" (copy) task
Warning: Unable to read "chosen.css" file (Error code: ENOENT). Use --force to continue.
Aborted due to warnings.
Run Code Online (Sandbox Code Playgroud)
奇怪的是,如果我用这个配置运行它:
copy: {
images: {
src: 'src/multiselect/lib/chosen.css',
// src: 'chosen.css',
dest: './built/css/',
flatten: true,
filter: 'isFile'
}
},
Run Code Online (Sandbox Code Playgroud)
它每次都有效.有没有人知道为什么?看起来这行代码出错了:
grunt.file.copy(src, dest, copyOptions);
Run Code Online (Sandbox Code Playgroud)
在grunt-contrib-copy任务中.任何帮助将不胜感激.
我正在尝试在复制时替换不同文件中的一些占位符.我的gruntfile工作正常,但添加进程选项来进行替换,它只是不起作用.以下是我的gruntfile的相关部分:
grunt.initConfig({
copy: {
js: {
files: [{
expand: true,
cwd: 'src/wp-content/themes/pilau-starter/',
src: ['**/*.js'],
dest: 'public/wp-content/themes/pilau-starter/'
}],
options: {
process: function ( content ) {
console.log( content );
content = content.replace( /pilauBreakpointLarge/g, breakpoints.large );
content = content.replace( /pilauBreakpointMedium/g, breakpoints.medium );
return content;
}
}
},
}
});
Run Code Online (Sandbox Code Playgroud)
可以在GitHub上的代码的上下文中理解这些路径:https://github.com/pilau/starter(公共目录未提交给repo,因为它是一个入门主题).这些路径是我原来的Gruntfile中的变量,并且在所有其他任务中都能正常工作.
所有的变量都设置好了.我已经包含了console.log( content )检查进程函数是否实际运行 - 它似乎不是,所以我猜它是基本语法.
有一个答案(/sf/answers/2002033211/)似乎解决了这个问题,但据我所知,这样做的方式就是糟糕的JS语法 - 不确定它是如何被标记为对.
--verbose 用于运行复制任务的输出:
Running "copy:js" (copy) task
Verifying property copy.js exists in config...OK
Files: src/wp-content/themes/pilau-starter/js/admin.js -> public/wp-content/themes/pilau-starter/js/admin.js …Run Code Online (Sandbox Code Playgroud) 我一直在尝试安装Grunt.当我运行grunt时,我收到以下消息和警告列表:
Local Npm module "grunt-contrib-copy" not found. Is it installed?
Local Npm module "grunt-contrib-uglify" not found. Is it installed?
Local Npm module "grunt-contrib-jshint" not found. Is it installed?
Local Npm module "grunt-contrib-less" not found. Is it installed?
Local Npm module "grunt-contrib-clean" not found. Is it installed?
Local Npm module "grunt-contrib-watch" not found. Is it installed?
Local Npm module "grunt-contrib-concurrent" not found. Is it installed?
Local Npm module "grunt-contrib-nodemon" not found. Is it installed?
Local Npm module "grunt-contrib-newer" not found. Is …Run Code Online (Sandbox Code Playgroud) node.js npm grunt-contrib-watch grunt-contrib-copy grunt-contrib-uglify
我知道我可以在grunt.config中设置一个任务,它将grunt-contrib-copy文件从src复制到dest,并查看Grunt文档,我知道我可以使用grunt.file.copy复制单个文件.
但是,是否可以在自定义注册任务中动态创建grunt-contrib-copy任务以适应从bash发送的参数?我想创建一个新目录grunt.file.mkdir("some/path/appfoldername"),然后将文件从另一个目标复制到该文件夹,但在运行自定义任务之前我不会知道文件夹名称.所以类似于:
grunt create_app:appfoldername
Run Code Online (Sandbox Code Playgroud)
所以我可以一次复制一个文件,但文件会改变,所以需要grunt-contrib-copy的强大功能,但具有自定义注册任务的灵活性.
如果我的解释不够清楚,我会想象这样的事情:
grunt.registerTask('createCopy', 'Create a copy', function(folderName) {
var cwd = grunt.template.process("some/path/to/app");
var src = grunt.template.process("some/path/to/src");
var dest = grunt.template.process("some/path/to/dest") + folderName;
grunt.task.run('copy: {
files: {
cwd: cwd,
src: src,
dest: dest
}
}');
}
Run Code Online (Sandbox Code Playgroud)
UPDATE
grunt.registerTask('mkapp', 'Create Application', function(appName) {
// Check appName is not empty or undefined
if(appName !== "" && appName !== undefined) {
// Require node path module, since not a global
var path = require("path");
// Resolve directory path using templates …Run Code Online (Sandbox Code Playgroud) 好吧,我已经坚持了两个星期,所以希望这里的其他人遇到过这个问题.我正在尝试使用Grunt来仅复制已更改的文件.我已经看过很多关于如何使用JSLINT和UGLIFY执行此操作的示例,但没有关于如何使用grunt-contrib-copy执行此操作的具体示例.
当您注册监视事件并将文件名传递给复制子任务时,文件名可以访问(我正在将其注销),但文件永远不会正确复制.
我希望它是一件我能忽视的简单事物.有人可以看看我的代码,看看我做错了什么?
//Gruntfile.js:
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
options: {
base: 'app',
dist: 'dist',
},
copy: {
changedFiles: {
expand: true,
dot: true,
cwd: '<%= options.base %>',
src: ['**/*.*'],
dest: '<%= options.dist %>/'
}
},
watch: {
options: {
nospawn: true,
//debounceDelay: 1000,
},
css: {
files: ['app/css/*.css',
'app/js/*.js'
],
tasks: ['copy:changedFiles'],
}
}
});
grunt.event.on('watch', function(action, filepath, target){
grunt.log.writeln('target: ', target + '\n filepath: ' + filepath + '\n action: has ' + action);
grunt.config('copy.changedFiles.src', new …Run Code Online (Sandbox Code Playgroud)