如何配置grunt复制任务以从子目录中排除.js文件

How to configure grunt copy task to exclude .js files from a subdirectory

本文关键字:子目录 排除 文件 js 任务 复制 何配置 配置 grunt      更新时间:2023-09-26

我使用grunt-contrib-copy将文件夹和文件从src文件夹复制到build文件夹。但我想从我的src目录中的应用程序子目录中排除所有.js文件。这是我的Gruntfile。但它是从应用程序目录的子目录中复制所有.js文件,而不是排除。我应该做什么改变才能让它发挥作用。

这是我的咕哝文件:

module.exports = function(grunt) {
  grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
    // Task configuration.
concat: {
  dist: {
    src: ['src/app/**/*.js'],
    dest: 'build/app.min.js'
  }
},
    copy: {
    main: {
      files: [
         //includes files within path and its sub-directories
            //{src: ['src/**', '!/src/app/**/*.js'], dest: 'build/', filter: 'isFile'}
        {expand: true, src: ['src/**', '!/src/app/**/*.js'], dest: 'build/', filter: 'isFile'}
      ]
    }
} 
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-contrib-copy');
 grunt.registerTask('default', ['concat', 'copy']);
};

参考:配置grunt复制任务以排除文件/文件夹

谢谢。

你能试着去掉感叹号后面的第一个斜杠吗?所以改变这个:

'!/src/app/**/*.js'

到此:

'!src/app/**/*.js'