Open frankleng opened 8 years ago
I've also stumbled upon this today and decided that the most painless way to follow the babel recommendations is to run everything with babel-node in development and when you're ready compile your backend js with babel and just copy everything you need to release folder.
So, now I have these lines in my npm scripts:
"clean": "rm -rf release",
"start": "babel-node server.js",
"release": "babel-node node_modules/.bin/gulp release"
And my gulpfile looks like this:
import gulp from 'gulp';
import babel from 'gulp-babel'
import filter from 'gulp-filter'
gulp.task('release', () => {
let path_list = ['{src,static}/**/*.*', 'package.json', 'LICENSE',
'!src/{containers,containers/**,components,components/**}'];
let filter_babel = filter(['src/**/*.js'], { restore: true });
return gulp.src(path_list)
.pipe(filter_babel)
.pipe(babel())
.pipe(filter_babel.restore)
.pipe(gulp.dest('release'));
});
Then, when you're ready to deploy, invoke npm install --production
in release folder and run server with just node.
@frankleng ask myself the same question, and it seems that @erikras had babel-node
before but on some reason switched to babel-register
https://github.com/erikras/react-redux-universal-hot-example/commit/a2e162fc5d6b1e1f33c7ea5b77b9d8d7e0f987bf. I didn't find any explanation from him but core team of babel
still highly recommend to not use babel-register
in production https://github.com/babel/example-node-server/issues/13.
@hyzhak, you probably know this already, but babel-node
is not meant for production either:
You should not be using babel-node in production. It is unnecessarily heavy, with high memory usage due to the cache being stored in memory. You will also always experience a startup performance penalty as the entire app needs to be compiled on the fly.
This is what I use ATM:
"start": "cross-env NODE_ENV=production node --harmony ./build/server",
"build:server": "rimraf ./build && babel src -d build --copy-files",
according to https://babeljs.io/docs/setup/#babel_register it's not meant for prod use.
guess they are encouraging people to precompile.
thinking the best way is to create another webpack build for the server code. thoughts?