如何让Grunt-Contrib-Copy复制相对于给定源路径的文件/目录 [英] How to get Grunt-Contrib-Copy to copy files/directories relative to given source path
问题描述
首次使用此任务以及我要实现的目标如下:
First time using this task and what I'm trying to achieve is the following:
从 src / js复制所有目录/文件/ bower_components / *
到 build / assets / js / vendor /
我'尝试使用 cwd
属性,但是当我使用它时它根本不起作用..我已将其设置为: src / js / bower_components /
I've tried using cwd
property but it doesn't work at all when I use it.. I've set it to: src/js/bower_components/
来自src
.
├── Gruntfile
└── src
└── js
└── bower_components
└── jquery
我目前得到:
.
├── Gruntfile
└── build
└── assets
└── js
└── vendor
src
└── js
└── bower_components
└── jquery
我想要什么
.
├── Gruntfile
└── build
└── assets
└── js
└── vendor
└──jquery
这是我目前的咕噜声任务
Here's my current grunt task
copy: {
main: {
src: 'src/js/bower_components/*',
dest: 'build/assets/js/vendor/',
expand: true,
}
},
感谢任何帮助
推荐答案
我已经设置了一个像这样的树的示例项目:
I've set up an example project with tree like this:
.
├── Gruntfile.js
├── package.json
└── src
└── js
└── foo.js
使用以下Gruntfile:
Using the below Gruntfile:
module.exports = function(grunt) {
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig({
copy : {
foo : {
files : [
{
expand : true,
dest : 'dist',
cwd : 'src',
src : [
'**/*.js'
]
}
]
}
}
});
grunt.registerTask('build', function(target) {
grunt.task.run('copy');
});
};
这给了我这样的结构:
.
├── Gruntfile.js
├── dist
│ └── js
│ └── foo.js
├── package.json
└── src
└── js
└── foo.js
当我更改 cwd
以便Gruntfile读取:
When I had changed cwd
so that the Gruntfile read:
module.exports = function(grunt) {
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);
grunt.initConfig({
copy : {
foo : {
files : [
{
expand : true,
dest : 'dist',
cwd : 'src/js',
src : [
'**/*.js'
]
}
]
}
}
});
grunt.registerTask('build', function(target) {
grunt.task.run('copy');
});
};
我得到了这个目录结构:
I got this dir structure:
.
├── Gruntfile.js
├── dist
│ └── foo.js
├── package.json
└── src
└── js
└── foo.js
所以好像是 cwd
做你需要的。设置 cwd $时,您可能会在
src / js / bower_components / *
处离开 src
c $ c>到 src / js / bower_components
?在这种情况下, src
应该读取类似 ** / * .js
的内容,但这取决于您真正需要的内容。
So it seems like cwd
does what you need. Maybe you left src
at src/js/bower_components/*
when setting cwd
to src/js/bower_components
? In that case, src
should read something like **/*.js
, but depending on what you really need.
这篇关于如何让Grunt-Contrib-Copy复制相对于给定源路径的文件/目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!