On Github jbavari / JavascriptBuildSystemShowdown
Created by Josh Bavari / @jbavari
Demo time!
Showing code/demo of Gruntfile.js located in root directory, then code/demo of Gulpfile.js in root dir, then broccoli commands, followed by brunch commands.Think the systems all being tools in a toolshed. Each tool is used differently. Some focused on strictly atomic tasks. Others focused on one pass through. No tool is wrong, just different approaches.
Grunt has a plugin to run Gulp tasks, and Gulp has a plugin to run Grunt tasks.
Each tool has strengths and weaknesses. Your job will be to identify which tool may be best suited for your needs.
//Install grunt command line tools npm install -g grunt-cli //Specify plugins by saving to package.json file npm install grunt-contrib-uglify --save-dev npm install grunt-contrib-concat --save-devEnlarge
grunt.initConfig({
our_file_list: ['./src/js/{Models,Controllers}/*.js', './src/js/index.js'],
uglify: {
build: {
src: 'js/reveal.js',
dest: 'js/reveal.min.js'
},
all: {
files: {
'js/compiled/file.js': '<%= our_file_list %>',
}
}
},
concat: {
dist: {
src: ['js/reveal.min.js', 'js/compiled/file.js'],
dest: 'dist/built.js',
},
}
});
Enlarge
{
"name": "my-project-name",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-nodeunit": "~0.3.3",
"grunt-contrib-uglify": "~0.4.0"
}
}
Enlarge
//Run all uglify targets grunt uglify //Execute uglify, but only the all target grunt uglify:allEnlarge
//Install grunt command line tools npm install -g gulp //Specify plugins by saving to package.json file npm install --save-dev gulp-uglify npm install --save-dev gulp-concatEnlarge
var gulp = require('gulp');
var concat = require('gulp-concat');
var uglify = require('gulp-uglify');
gulp.task('scripts', function() {
// Minify and copy all JavaScript (except vendor scripts)
return gulp.src(paths.scripts)
.pipe(uglify())
.pipe(concat('all.min.js'))
.pipe(gulp.dest('build/js'));
});
Enlarge
//Run all uglify targets gulp scriptsEnlarge
Havent used long enough to form any
The first build system widely used and available. Uses skeletons (like scaffolding) to create app directory structure.
//Create new skeleton of angular app brunch new https://github.com/scotch/angular-brunch-seed myapp //Install bower packages (css/js/etc) bower install //tell Brunch to watch your project and incrementally rebuild it when source files are changed brunch watch --server //builds a project for distribution. By default it enables minification brunch build --productionEnlarge
Mainly focused on Ember.js apps, and ships with Ember CLI