Skip to content

Instantly share code, notes, and snippets.

@dennib
Last active April 8, 2021 19:43
Show Gist options
  • Save dennib/6f1f9aa9b59596710f62c1ef22a655f4 to your computer and use it in GitHub Desktop.
Save dennib/6f1f9aa9b59596710f62c1ef22a655f4 to your computer and use it in GitHub Desktop.

Revisions

  1. dennib revised this gist May 9, 2019. 1 changed file with 12 additions and 0 deletions.
    12 changes: 12 additions & 0 deletions server.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    const express = require('express');
    const app = express();

    app.use(express.static('public'));
    app.get('/', function(req, res) {
    res.send('Hello World!');
    });

    // Server Listening
    app.listen(3000, function() {
    console.log('App listening on port 3000!');
    });
  2. dennib revised this gist May 9, 2019. No changes.
  3. dennib created this gist May 9, 2019.
    51 changes: 51 additions & 0 deletions gulpfile.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    const gulp = require('gulp');
    const sass = require('gulp-sass');
    const browserSync = require('browser-sync');
    const nodemon = require('gulp-nodemon');

    sass.compiler = require('node-sass');

    // Sass compilation
    gulp.task('sass', function() {
    return gulp
    .src('./sass/**/*.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest('./css'));
    });

    // Sass watching, depending on "sass" task
    gulp.task('sass:watch', function() {
    gulp.watch('./sass/**/*.scss', gulp.series('sass'));
    });

    // Nodemon task:
    // Start nodemon once and execute callback (browser-sync)
    gulp.task('nodemon', cb => {
    let started = false;
    return nodemon({
    script: 'server.js'
    }).on('start', () => {
    if (!started) {
    cb();
    started = true;
    }
    });
    });

    // BrowserSync task:
    // calls nodemon tasks and pass itself as callback
    gulp.task(
    'browser-sync',
    gulp.series('nodemon', () => {
    browserSync.init(null, {
    proxy: 'http://localhost:3000',
    files: ['public/**/*.*'],
    port: 5000
    });
    })
    );

    // Dev Task:
    // Parallel execution of browser-sync/nodemon
    // and sass watching
    gulp.task('default', gulp.parallel('browser-sync', 'sass:watch'));