配置grunt copy任务以排除文件/文件夹 [英] Configure grunt copy task to exclude files/folders

查看:1371
本文介绍了配置grunt copy任务以排除文件/文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我安装了grunt任务 grunt-contrib-copy 。我将它嵌入到我的 Gruntfile.js 中并通过 grunt.loadNpmTasks('grunt-contrib-copy');



目前我使用以下配置创建一个包含我的js文件/文件夹子集的文件夹。

  copy:{
options:{
processContent:[],
processContentExclude:['build / **','bin / **','。 *','* .orig','* .bak','。* / **','* .log','dist / **','test / **','dev / 'pyserver / **','node_modules / **','doc / **']
},
du:{
文件:[
{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 copy它退出与以下错误消息:

 复制Gruntfile.js  - > output / Gruntfile.js 
警告:处理Gruntfile.js文件时出错。使用--force继续。

我想排除 Gruntfile.js 以及 js / ** / * 中的所有 *。文件。尝试使用!(。less),!.less,!(*。less),!(./ Grunfile.js),!(* Gruntfile.js)。 ..但没有什么工作。添加到 processContentExclude 数组,但没有成功。



那么如何排除 Gruntfile.js 和文件夹结构中的所有更少的文件 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 /'} code>是一个新的复制步骤,将所有文件从 ./ 复制到输出。这对我来说不是必需的,因为上面的行已经将所需的文件复制到 output / toolkit



所以下面两行做的工作。不需要选择或任何其他。要阻止 *。less 文件'!** / *。less' >

  files:[
{src:['.conf1','.conf2','config.js'],dest :'output / toolkit /',filter:'isFile'},
{src:['css / **','img / **','js / **','release / ,'lib / **','locale / **','!** / *。less'],dest:'output / toolkit /'}
]


I have installed the grunt task grunt-contrib-copy. I embedd it in my Gruntfile.js and load the task via grunt.loadNpmTasks('grunt-contrib-copy');.

Currently I use following configuration to create a folder with a subset of my js files/folders.

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/'}
                ]
            }
        }

This works fine, but everytime I run grunt copy it exits with the following error message:

Copying Gruntfile.js -> output/Gruntfile.js
Warning: Error while processing "Gruntfile.js" file. Use --force to continue.

I would like to exclude Gruntfile.js and all *.less files in js/**/*. Tried it with !(.less), !.less, !(*.less), !(./Grunfile.js), !(*Gruntfile.js) ... But nothing works. Added it to the processContentExclude array, but without success too.

So how can I exclude the Gruntfile.js and all less files in the folder structure js/**/*?

解决方案

Found the solution:

There is no need for these lines:

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/'}
       ]

because {expand: true, cwd: './', src: ['**'], dest: 'output/'} is a new copy step, copying all files from ./ to output. Which is for me not needed, because the above lines are already copying the required files to output/toolkit.

So the following two lines does the job. No need for options or anything else. To keep out the *.less files '!**/*.less' does the job.

files: [ 
          {src: ['.conf1', '.conf2', 'config.js'], dest: 'output/toolkit/', filter: 'isFile'},
          {src: ['css/**', 'img/**', 'js/**', 'release/**', 'lib/**', 'locale/**', '!**/*.less'], dest: 'output/toolkit/'}
       ]

这篇关于配置grunt copy任务以排除文件/文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆