Search code examples
gulpbabeljs

babel output filename option


What is the babel option to rename output transpiled file.

With babel-cli it is -o

babel script.js -o script.transpiled.js

Is there a corresponding babel option that can be used with gulp-babel ?


Solution

  • As filename is handled for you by gulp-babel, you might want to use gulp-rename as an additional pipe

    var rename = require('gulp-rename');
    
    gulp.task('default', () =>
        gulp.src('script.js')
            .pipe(babel({
                presets: ['@babel/env']
            }))
            .pipe(rename(function(path) {
              path.basename = 'script.transpiled';
              path.extname = '.js';
            }))
            .pipe(gulp.dest('dist'))
    );