Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var gulp = require('gulp');
- var autoprefixer = require('gulp-autoprefixer');
- var plumber = require('gulp-plumber');
- var gutil = require('gulp-util');
- var concat = require('gulp-concat');
- var cleanCSS = require('gulp-clean-css');
- var rename = require("gulp-rename");
- var sass = require('gulp-sass');
- var uglify = require('gulp-uglify');
- var sourcemaps = require("gulp-sourcemaps");
- var browserSync = require('browser-sync').create();
- var nodemon = require('gulp-nodemon');
- // Error Handling
- var gulp_src = gulp.src;
- gulp.src = function() {
- return gulp_src.apply(gulp, arguments)
- .pipe(plumber(function(error) {
- // Output an error message
- gutil.log(gutil.colors.red('Error (' + error.plugin + '): ' + error.message));
- // emit the end event, to properly end the task
- this.emit('end');
- })
- );
- };
- // Scripts
- gulp.task('scripts', function() {
- return gulp.src('./public/js/main.js')
- .pipe(concat('main.min.js'))
- .pipe(gulp.dest('./public/js/'))
- .pipe(uglify())
- .pipe(gulp.dest('./public/js/'))
- });
- // Styles
- gulp.task('styles', function() {
- return gulp.src('./public/sass/*.scss')
- .pipe(sass())
- .pipe(autoprefixer('last 2 versions'))
- .pipe(sourcemaps.init())
- .pipe(gulp.dest('./public/css/'))
- .pipe(cleanCSS())
- .pipe(sourcemaps.write())
- .pipe(concat("main.css", {newLine: ""}))
- .pipe(gulp.dest('./public/css/'))
- });
- // BrowserSync
- gulp.task('browserSync', ['nodemon'], function() {
- browserSync.init({
- proxy: "http://localhost:3000",
- port: 4000,
- open: false,
- notify: true,
- // snippetOptions: {
- // rule: {
- // match: /<\/body>/i,
- // fn: function (snippet, match) {
- // return snippet + match;
- // }
- // }
- // }
- })
- })
- // Default Tasks
- gulp.task('default', ['browserSync'], function () {
- gulp.watch('./views/**/*.ejs', browserSync.reload);
- gulp.watch('./public/**/*.js', browserSync.reload);
- gulp.watch('./public/**/*.scss', browserSync.reload);
- gulp.watch(['./routes/**/*.js', './app.js', './bin/www'], ['bs-delay']);
- });
- // Give nodemon time to restart
- gulp.task('bs-delay', function () {
- setTimeout(function () {
- browserSync.reload({ stream: false });
- }, 1000);
- });
- // Nodemon
- gulp.task('nodemon', function (cb) {
- var started = false;
- return nodemon({
- script: './bin/www',
- ext: 'js',
- ignore: ['public/**/*.js'],
- env: {
- 'NODE_ENV': 'development',
- 'DEBUG': 'appname:*'
- }
- }).on('start', function () {
- //avoid nodemon being started multiple times
- if (!started) {
- cb();
- started = true;
- }
- })
- .on('crash', function() {
- // console.log('nodemon.crash');
- })
- .on('restart', function() {
- // console.log('nodemon.restart');
- })
- .once('quit', function () {
- // handle ctrl+c without a big weep
- process.exit();
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment