![](/img/trans.png)
[英]How to configure grunt copy task to exclude .js files from a subdirectory
[英]Configure grunt copy task to exclude files/folders
我已经安装了grunt任务grunt-contrib-copy
。 我将它Gruntfile.js
我的Gruntfile.js
并通过grunt.loadNpmTasks('grunt-contrib-copy');
加载任务grunt.loadNpmTasks('grunt-contrib-copy');
。
目前,我使用以下配置来创建包含我的js文件/文件夹子集的文件夹。
copy: {
options: {
processContent: [],
processContentExclude: ['build/**', 'bin/**', '.*', '*.orig', '*.bak', '.*/**', '*.log', 'dist/**', 'test/**', 'dev/**', 'pyserver/**', 'node_modules/**', 'doc/**']
},
du: {
files: [
{src: ['.conf1', '.conf2', './config.js'], dest: 'output/toolkit/', filter: 'isFile'},
{src: ['./css/**/*', './img/**/*', './js/**/*', './release/**/*', './lib/**/*', './locale/**/*'], dest: 'output/toolkit/'},
{expand: true, cwd: './', src: ['**'], dest: 'output/'}
]
}
}
这工作正常,但每次我运行grunt副本它退出时出现以下错误消息:
Copying Gruntfile.js -> output/Gruntfile.js
Warning: Error while processing "Gruntfile.js" file. Use --force to continue.
我想在js/**/*
排除Gruntfile.js
和所有*.less
文件。 尝试了!(.less), !.less, !(*.less), !(./Grunfile.js), !(*Gruntfile.js)
......但没有任何作用。 将它添加到processContentExclude
数组中,但也没有成功。
那么如何在文件夹结构js/**/*
排除Gruntfile.js
和所有较少的文件?
找到解决方案:
这些线路没有必要:
files: [
{src: ['.conf1', '.conf2', './config.js'], dest: 'output/toolkit/', filter: 'isFile'},
{src: ['./css/**/*', './img/**/*', './js/**/*', './release/**/*', './lib/**/*', './locale/**/*'], dest: 'output/toolkit/'},
{expand: true, cwd: './', src: ['**'], dest: 'output/'}
]
因为{expand: true, cwd: './', src: ['**'], dest: 'output/'}
是一个新的复制步骤,将所有文件从./
复制到output
。 这对我来说不需要,因为上面的行已经将所需的文件复制到output/toolkit
。
所以以下两行就是完成这项工作的。 不需要选项或其他任何东西。 为了防止*.less
文件'!**/*.less'
*.less
'!**/*.less'
完成工作。
files: [
{src: ['.conf1', '.conf2', 'config.js'], dest: 'output/toolkit/', filter: 'isFile'},
{src: ['css/**', 'img/**', 'js/**', 'release/**', 'lib/**', 'locale/**', '!**/*.less'], dest: 'output/toolkit/'}
]
我想要排除我的副本中的所有.gz文件,这个选项完成了所有文件夹的工作
{
expand: true,
cwd: './build/www/',
src: [ '**', '!**/*.gz' ],
dest: './mydDest'
}
所以可能会尝试!**/*.less, !gruntfile.js
(没有parens)
如果您可以自由更改为不同的Grunt任务:
还有https://github.com/clavery/grunt-copy-to ,它有一个明确的“ignore”选项来指定要省略的文件和目录。 Github中的README显示了一个包含忽略选项的示例配置。
它与常规副本的工作方式略有不同,因为它符合修改时间。 但这实际上可能是受欢迎的(这是我的情况)。
来自README:
与grunt-contrib-copy类似,但只复制较新的文件并保持复制文件的修改时间。 用于创建构建目录,以后可以使用依赖于文件修改时间的工具同步。
(我只是该项目的用户(至少到目前为止)。)
我认为应该这样做。 不需要/**/*
。 /**
涵盖路径及其子目录中的所有文件
{src: ['./css/**', './img/**', './js/**', './release/**', './lib/**', './locale/**'], dest: 'output/toolkit/'},
{expand: true, cwd: './', src: ['**'], dest: 'output/'}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.