Skip to content

Instantly share code, notes, and snippets.

@long-lazuli
Created August 4, 2015 14:17
Show Gist options
  • Save long-lazuli/bfbb7cae5483bf8086e1 to your computer and use it in GitHub Desktop.
Save long-lazuli/bfbb7cae5483bf8086e1 to your computer and use it in GitHub Desktop.
my web-app starter
var browserSync = require('browser-sync').create();
var gulp = require('gulp');
var del = require('del');
var concat = require('gulp-concat'),
filesize = require('gulp-filesize'),
gutil = require('gulp-util'),
order = require('gulp-order');
rename = require('gulp-rename'),
sass = require('gulp-sass'),
sourcemaps = require('gulp-sourcemaps'),
uglify = require('gulp-uglify');
var paths = {
mainScript: 'sources/js/app.js',
scripts: 'sources/js/**/*.js',
stylesheets: 'sources/scss/**/*.scss'
};
gulp.task('default', ['build', 'start']);
gulp.task('build', ['scripts', 'stylesheets']);
gulp.task('start', ['serve', 'watch']);
gulp.task('serve', function() {
browserSync.init({ server: "./public" });
});
// Rerun the task when a file changes
gulp.task('watch', function() {
gulp.watch(paths.scripts, ['scripts']);
gulp.watch(paths.stylesheets, ['stylesheets']);
gulp.watch([
"public/*.html",
"public/**/*.js",
"public/**/*.css"
]).on('change', browserSync.reload);
});
gulp.task('scripts', ['clean:scripts'], function() {
gulp.src(paths.scripts)
.pipe(order([ paths.mainScript, paths.scripts]))
// concat
.pipe(sourcemaps.init())
.pipe(concat('app.js'))
.pipe(filesize())
.pipe(gulp.dest('public/scripts'))
// minify
.pipe(uglify().on('error', gutil.log))
.pipe(rename({extname: '.min.js'}))
.pipe(sourcemaps.write('./'))
.pipe(filesize())
.pipe(gulp.dest('public/scripts'));
});
gulp.task('stylesheets', ['clean:stylesheets'], function () {
gulp.src(paths.stylesheets)
.pipe(sourcemaps.init())
.pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
.pipe(sourcemaps.write('./'))
.pipe(filesize())
.pipe(gulp.dest('public/stylesheets'));
});
gulp.task('clean', ['clean:scripts', 'clean:stylesheets']);
gulp.task('clean:scripts', function() {
del(['public/scripts']);
});
gulp.task('clean:stylesheets', function() {
del(['public/stylesheets']);
});
{
"name": "application-name",
"version": "1.0.0",
"description": "Application Description",
"main": "public/index.html",
"author": "Author Name",
"license": "ISC",
"dependencies": {
"browser-sync": "^2.8.1",
"del": "^1.2.0",
"gulp": "^3.9.0",
"gulp-concat": "^2.6.0",
"gulp-filesize": "0.0.6",
"gulp-order": "^1.1.1",
"gulp-rename": "^1.2.2",
"gulp-sass": "^2.0.4",
"gulp-sourcemaps": "^1.5.2",
"gulp-uglify": "^1.2.0",
"gulp-util": "^3.0.6"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment