G运行t: 运行 每个文件而不是整个目录的 babel 任务

Grunt: run babel task for each file instead of entire directory

我有这个 G运行 文件,它 "watch" 用于 src/ 目录中的 .js 文件,当其中一个文件被修改时,babel (https://github.com/babel/grunt-babel) 任务运行s 在 dist/ 目录中生成 ES5 文件:

module.exports = function(grunt) {

    require('load-grunt-tasks')(grunt);
    grunt.initConfig({
        babel: {
            options: {
                sourceMap: false
            },

            dist: {
                 files: [{
                    expand: true,
                    cwd: 'src/',
                    src: ['*.js'],
                    dest: 'dist/',
                    ext: '.js'
                }]
            }

        },

        watch: {
            ej6: {
                files: "src/*.js",
                tasks: ['babel']
            }
        }
    });

    grunt.loadNpmTasks('grunt-contrib-watch');

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

};

是否可以仅针对该特定文件查看 src/ 目录和 运行 babel 任务?因为,如果我在 src/ 路径中有 'n' 个文件,脚本将重新生成所有这些文件。

尝试使用这个包https://www.npmjs.com/package/grunt-newer

我使用 gulp 等效方法,遵循与您描述的类似方法。