首次使用此任务以及我想要实现的目标如下:
将所有目录/文件从src/js/bower_components/*
复制到build/assets/js/vendor/
我尝试过使用cwd
属性,但在使用它时根本不起作用..我已将其设置为: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
这是我目前的咕噜声任务
copy: {
main: {
src: 'src/js/bower_components/*',
dest: 'build/assets/js/vendor/',
expand: true,
}
},
感谢您的帮助
答案 0 :(得分:20)
我已经设置了一个像这样的树的示例项目:
.
├── Gruntfile.js
├── package.json
└── src
└── js
└── foo.js
使用以下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读取时:
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');
});
};
我有这个目录结构:
.
├── Gruntfile.js
├── dist
│ └── foo.js
├── package.json
└── src
└── js
└── foo.js
所以似乎cwd
可以满足您的需求。在将src
设置为src/js/bower_components/*
时,您可能会在cwd
离开src/js/bower_components
吗?在这种情况下,src
应该读取类似**/*.js
的内容,但取决于您真正需要的内容。