我的 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 thefoo/
subdirectory, butfoo/**/*.js
will match all files ending with.js
in thefoo/
subdirectory and all of its subdirectories.
... 在 Globbing patterns 中咕噜文档。
关于gruntjs - 使用 babel 和 grunt 递归地将 ES6 转换为 ES5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41551692/