Skip to content

Instantly share code, notes, and snippets.

@hedgerh
Created July 2, 2015 00:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hedgerh/8fb1e9e4625dd7048fe0 to your computer and use it in GitHub Desktop.
Save hedgerh/8fb1e9e4625dd7048fe0 to your computer and use it in GitHub Desktop.
Simple gulp build system
'use strict';
var path = require('path');
var gulp = require('gulp'),
browserify = require('browserify'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
sourcemaps = require('gulp-sourcemaps'),
autoprefixer = require('gulp-autoprefixer'),
minifycss = require('gulp-minify-css'),
sass = require('gulp-sass'),
uglify = require('gulp-uglify'),
del = require('del'),
livereload = require('gulp-livereload'),
nodemon = require('gulp-nodemon');
var AUTOPREFIXER_BROWSERS = [
'ie >= 9',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
];
gulp.task('styles', function() {
return gulp.src('./public/assets/sass/main.scss')
.pipe(sass({
includePaths: require('node-bourbon').includePaths
}))
.pipe(autoprefixer(AUTOPREFIXER_BROWSERS))
.pipe(minifycss())
.pipe(gulp.dest('./public/assets/css'));
});
gulp.task('client', function() {
browserify('./client/app.js')
.transform(babelify)
.transform(reactify)
.bundle()
.pipe(source('bundle.js'))
.pipe(buffer())
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(uglify())
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./public/assets/js'));
});
gulp.task('nodemon', function() {
process.env.NODE_ENV = 'development';
nodemon({
script: './index.js',
ext: 'html js',
ignore: [
'node_modules/',
'public/'
]
});
});
gulp.task('clean', function() {
del([
'./public/assets/css/**/*',
'./public/assets/js/**/*'
]);
});
gulp.task('build', ['clean'], function() {
gulp.start(['styles', 'client']);
});
gulp.task('watch', function() {
gulp.watch('./public/assets/sass/**/*.scss', ['styles']);
gulp.watch('./client/**/*.js', ['client']);
gulp.watch('./public/assets/**/*', livereload.changed);
nodemon({
script: './index.js',
ext: 'html js',
ignore: [
'node_modules/',
'public/'
]
}).on('restart', livereload.changed);
});
gulp.task('dev', ['watch'], function() {
console.log(livereload.server);
livereload.listen();
});
{
"name": "simple",
"version": "0.1.0",
"description": "A demo app",
"main": "index.js",
"scripts": {
"start": "node index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": ""
},
"author": "",
"license": "ISC",
"bugs": {
"url": ""
},
"homepage": ",
"dependencies": {
"angular": "^1.4.1"
"express": "^4.12.4"
},
"devDependencies": {
"browserify": "^10.2.3",
"del": "^1.2.0",
"gulp": "^3.8.11",
"gulp-autoprefixer": "^2.3.0",
"gulp-livereload": "^3.8.0",
"gulp-minify-css": "^1.1.1",
"gulp-nodemon": "^2.0.3",
"gulp-sass": "^2.0.1",
"gulp-sourcemaps": "^1.5.2",
"gulp-uglify": "^1.2.0",
"node-bourbon": "^4.2.2",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment