onehilltech / blueprint

solid framework for building APIs and backend services
125 stars 26 forks source link

Support for Babel #47

Closed hilljh82 closed 7 years ago

hilljh82 commented 7 years ago

Babel allows developers to use features in JavaScript that many not be available in Node.js. We should integrate Babel into Blueprint.js so we can leverage new JavaScript features when implementing our applications.

DannyPeck commented 7 years ago

How are you planning to integrate Babel, were you envisioning something similar to how Ember.js has integrated it?

technetos commented 7 years ago

In the past I have setup package.json fields to automatically call gulp to orchestrate babel for automatic transpiling of es6 code into es5 on any change to any file specified in gulp.js:

// gulp.js
(function() {
  'use strict';
  var gulp = require('gulp');
  var order = require('gulp-order');
  var concat = require('gulp-concat');
  var plumber = require('gulp-plumber');
  var sourcemaps = require('gulp-sourcemaps');
  var babel = require('gulp-babel');
  var connect = require('gulp-connect');

  gulp.task('bundle', bundle);
  gulp.task('start-web-server', startWebServer);
  gulp.task('watch', watch);
  gulp.task('default', ['bundle', 'start-web-server', 'watch']);

  ////////////////////

  var jsFiles = [
    'app/**/*.js',
    '!app/bower_components/**/*',
    '!app/content/bundle.js'
  ];

  function bundle() {
    return gulp.src(jsFiles)
      .pipe(order([
        'app/app.module.js',              // put the main module first
        'app/**/*.module.js',             // followed by all other modules
        'app/**/*.js'                     // and all other JS files
      ], { base: './' }))
      .pipe(plumber())                    // restart gulp on error
      .pipe(sourcemaps.init())            // let sourcemaps watch this pipeline
      .pipe(babel({
        presets: ['es2015']
      }))                                 // transpile into ES5 for browsers
      .pipe(concat('bundle.js'))          // concatenate all JS files
      .pipe(sourcemaps.write('.'))        // emit the .map file for debugging
      .pipe(gulp.dest('app/content'));
  }

  function startWebServer() {
    connect.server({
      root: 'app',
      port: 8000
    });
  }

  function watch() {
    gulp.watch(['app/**/*', 'gulpfile.js'], ['bundle']);
  }
})();

And in the script section of my package.json:

"scripts": {
    "start": "gulp",
    "prestart": "npm install"
}

Letting me simply call: $ npm start automatically transpiling my code and installing any necessary node modules all in 1 command.

Thats just my 2 cents.

hilljh82 commented 7 years ago

Give that Node 6 is now the minimum supported version and has many of the enhancements we were hoping to gain from using Babel, we are going to close this issue.