使用 babel 和 grunt 递归地将 ES6 转换为 ES5

Recursively convert ES6 to ES5 using babel with grunt

我的 grunt 文件如下:

module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: {
  js: ['src/*.min.js']
},
babel: {
   files: {
       expand: true,
       src: ['src/*.js','src/*/*.js','src/*/*/*.js'],
       ext: '-modified.js'
   },
   options: {
       sourceMap: false,
       presets: ['babel-preset-es2015']
   }
},
 watch: {
  tasks: ['babel']
}

});
grunt.registerTask('default', ['clean','babel']);
};

是否有更好的方法来配置 "src" 以便递归地找出 src 文件夹和子文件夹中的 js 文件并转译这些文件:

 src: ['src/*.js','src/*/*.js','src/*/*/*.js']

这三种通配模式:

src: ['src/*.js','src/*/*.js','src/*/*/*.js']

...可以换成一个:

src: ['src/**/*.js']

查看正文:

All most people need to know is that foo/*.js will match all files ending with .js in the foo/ subdirectory, but foo/**/*.js will match all files ending with .js in the foo/ subdirectory and all of its subdirectories.

... 在 grunt 文档的 Globbing patterns 中。