排除由grunt contrib jshint缩小的.spec文件

Exclude .spec files minified by grunt-contrib-jshint

本文关键字:spec 文件 缩小 jshint grunt contrib 排除      更新时间:2023-09-26

我正在使用yeoman角度生成器。在这个生成器中,测试被放置在一个单独的文件夹'test'中。我宁愿把它们和我的.js文件放在同一个文件夹里。我给他们起了个名字.spec.js。我需要在我的Gruntfile.js文件中修复这个问题,这样它们就不会包含在缩小、jshint等中

我是否可以排除以.spec.js结尾的文件?

// Make sure there are no obvious mistakes
jshint: {
  options: {
    jshintrc: '.jshintrc',
    reporter: require('jshint-stylish')
  },
  all: {
    src: [
      'Gruntfile.js',
      '<%= yeoman.app %>/scripts/{,*/}*.js'
    ]
  },
  test: {
    options: {
      jshintrc: 'test/.jshintrc'
    },
    src: ['test/spec/{,*/}*.js']
  }
},

在表达式前面使用!可以忽略它:

E.g!**/*.spec.js

在您的情况下

all: {
    src: [
      '!**/*.spec.js',
      'Gruntfile.js',
      '<%= yeoman.app %>/scripts/{,*/}*.js'
    ]
  },
  test: {
    options: {
      jshintrc: 'test/.jshintrc'
    },
    src: ['!**/*.spec.js','test/spec/{,*/}*.js']
  }