Can't make object imports in ES6 modules work with Gulp, Browserify and Babelify -


i enjoy es6 modules i'm having hard time making them work browserify , enhanced object literals.

i've created reduced test case sum issue.

here gulpfile:

var gulp = require('gulp'); var babelify = require('babelify'); var browserify = require('browserify'); var buffer = require('vinyl-buffer'); var source = require('vinyl-source-stream');  gulp.task('scripts', function() {   var b = browserify({     entries: 'main.js',     debug: true   })   .transform(babelify)    return b.bundle()   .pipe(source('bundle.js'))   .pipe(buffer())   .pipe(gulp.dest('./')); });  gulp.task('default', ['scripts']); 

its goal transform es6 modules browserify , transpile es6 es5.

now, have no issue basic imports, can't make work object imports. let's have 2 files:

utils.js

let utils = {   sayhi() {     console.log('hi');   } } 

main.js

import utils './utils';  utils.sayhi(); 

this fire error: uncaught typeerror: _utils2.default.sayhi not function

and @ point can't find decent workaround. appreciated!

you not exporting utils.js, there nothing import.

if want able import object written, have make default export:

export default utils; 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -