I use Gulp as task manager and Babel for convert my ES6 program to a version that is understandable for browsers, not for Node!
const gulp = require('gulp');
const babel = require('gulp-babel');
gulp.task('default', () =>
gulp.src('src/app.js')
.pipe(babel({
presets: ['es2015']
}))
.pipe(gulp.dest('dist'))
);
and in src/app.js
I have:
import { square, diag } from 'lib';
//Some code here....
But, when I run the gulp, it make a file in dist
but it converts import
which is in app.js
file to require
keyword that is not understandable for browsers... I thought bable will merge imported
files in src/app.js
to one file in dist
How can I convert my library code to be supported by browsers using Babel?