簡體   English   中英

Grunt:為每個文件而不是整個目錄運行babel任務

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

我有這個Grunfile,它可以“監視” src /目錄中的.js文件,並在其中一個被修改時運行babel( https://github.com/babel/grunt-babel )任務來生成ES5文件在dist /目錄中:

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等效項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM