简体   繁体   中英

grunt-babel not working as multi-task

The following config works as expected, but when the //build: { stuff is uncommented it either silently fails, or it does something unexpected to me.

    babel: {
        //build: {
            options: {
                sourceMap: true,
                presets: ['es2015']
            },
            dist: {
                files: [{
                    expand: true,
                    cwd: 'build/src/app',
                    src: ['**/*.js'],
                    dest: 'build/src/es5-app'
                }]
            }
        //}
    },

So, with //build: { commented out, the es5-app directory is created at build/src , but with //build: { uncommented, the directory is not created. In both instances grunt is run as grunt babel , and it returns Done, without errors .

Since grunt-babel is registered as a multi task, dist is actually the name of the target, with files being at the first level of the config. So when you run babel without build , it's actually running babel:dist (which you should see in the log).

For it to work the way you want, you would need something like the following:

babel: {
    options: {
        sourceMap: true,
        presets: ['es2015']
    },
    dist: {
        files: [{
            expand: true,
            cwd: 'build/src/app',
            src: ['**/*.js'],
            dest: 'build/src/es5-app'
        }]
    }
    build: {
        files: [{
            expand: true,
            cwd: 'build/src/app/test',
            src: ['test/**/*.js'],
            dest: 'build/test/es5-app'
        }]
    }
},

This would allow you to run either babel:dist or babel:build.

See http://gruntjs.com/creating-tasks for more information on multi tasks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM