Answer the question
In order to leave comments, you need to log in
How to make NodeJS server understand es6 import and export?
I am using gulp, babelify and browserify to compile the client side:
gulp.task('buildApp', function() {
return browserify('src/js/main.js')
.transform(babelify)
.bundle()
.pipe(source('main.js')) // gives streaming vinyl file object
.pipe(buffer()) // <----- convert from streaming to buffered vinyl file object
.pipe(uglify()) // now gulp-uglify works
.pipe(gulp.dest('./dist'));
});
gulp.task('server', () => {
return gulp.src('server/server.js')
.pipe(babel({
presets: ['es2015', 'react']
}))
.pipe(gulp.dest('./dist'));
});
Answer the question
In order to leave comments, you need to log in
Konstantin Kitmanov and Aves from babel-register were close, only it was in babel 5, now it's different.
Create .babelrc
{
"presets": ["es2015"],
}
require('babel-core/register');
require('./server');
Node version?
If LTS then it should pick up immediately (if there is "use strict"), if it's younger, then the --harmony key is needed
This is not how it should be done on the server. And how - it is written on the off. website: https://babeljs.io/docs/usage/require/
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question