Last active
November 17, 2015 14:20
-
-
Save joms/6a653c0ab68f5460c052 to your computer and use it in GitHub Desktop.
Gulp-tasks for compiling ES6 to ES5 and concating for Fuse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"parser": "babel-eslint", | |
"rules": { | |
"strict": 0 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var babel = require('gulp-babel'); | |
var concat = require('gulp-concat'); | |
var eslint = require('gulp-eslint'); | |
var gulp = require('gulp'); | |
var inject = require('gulp-inject-string'); | |
var watch = require('gulp-watch'); | |
var config = { | |
'dest': 'dist/', | |
'files': [ | |
'src/**/*.js', | |
'src/**/*.jsx' | |
] | |
} | |
var requires = [ | |
'var Observable = require("FuseJS/Observable");' | |
] | |
// Parse the required packages | |
function insertRequire(){ | |
var str = ''; | |
for (var i = 0; i < requires.length; i++) { | |
str += '\n'+requires[i]; | |
} | |
return str; | |
} | |
// Lint all files | |
gulp.task('lint', function () { | |
return gulp.src(config.files) | |
// eslint() attaches the lint output to the eslint property | |
// of the file object so it can be used by other modules. | |
.pipe(eslint()) | |
// eslint.format() outputs the lint results to the console. | |
// Alternatively use eslint.formatEach() (see Docs). | |
.pipe(eslint.format()) | |
// To have the process exit with an error code (1) on | |
// lint error, return the stream and pipe to failAfterError last. | |
.pipe(eslint.failAfterError()); | |
}); | |
// Watch files for changes | |
gulp.task('watch', function () { | |
watch(config.files, function(){ | |
// Run build upon change | |
gulp.start('build'); | |
}); | |
}); | |
// Define build task, run lint | |
gulp.task('build', ['lint'], function(){ | |
return gulp.src(config.files) | |
.pipe(babel({ | |
presets: ['es2015'], | |
plugins: ['transform-es2015-modules-commonjs'] | |
})) | |
// Inject requires into the javascript | |
.pipe(inject.after('"use strict";', insertRequire())) | |
// Concat all files into app.js | |
.pipe(concat('app.js')) | |
.pipe(gulp.dest(config.dest)); | |
}); | |
// Initialize the default task | |
gulp.task('default', ['build', 'watch']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"main": "gulpfile.js", | |
"dependencies": { | |
"babel-eslint": "latest", | |
"babel-preset-es2015": "latest", | |
"babelify": "latest", | |
"gulp": "latest", | |
"gulp-babel": "latest", | |
"gulp-concat": "latest", | |
"gulp-eslint": "latest", | |
"gulp-inject-string": "latest", | |
"gulp-watch": "latest" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment