gpt4 book ai didi

javascript - 如何让 Grunt-Contrib-Copy 复制相对于给定源路径的文件/目录

转载 作者:可可西里 更新时间:2023-11-01 01:17:55 26 4
gpt4 key购买 nike

第一次使用这个任务,我想要实现的是:

将所有目录/文件从 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

这是我当前的 grunt 任务

copy: {
main: {
src: 'src/js/bower_components/*',
dest: 'build/assets/js/vendor/',
expand: true,
}
},

感谢您的帮助

最佳答案

我已经用这样的树设置了一个示例项目:

.
├── 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 可以满足您的需求。也许你在将 cwd 设置为 src/js/bower_components 时将 src 留在了 src/js/bower_components/* ?在这种情况下,src 应该读取类似于 **/*.js 的内容,但这取决于您真正需要什么。

关于javascript - 如何让 Grunt-Contrib-Copy 复制相对于给定源路径的文件/目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22697919/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com