Skip to content

Instantly share code, notes, and snippets.

@Azadehkhojandi
Last active May 16, 2018 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Azadehkhojandi/bd68de94337b83469fc76a75d52f940d to your computer and use it in GitHub Desktop.
Save Azadehkhojandi/bd68de94337b83469fc76a75d52f940d to your computer and use it in GitHub Desktop.
Gulp webserver boilerplate
"use strict";
var gulp = require('gulp');
var connect = require('gulp-connect'); //Runs a local dev server
var open = require('gulp-open'); //Open a URL in a web browser
var config = {
port: 9005,
url: 'http://localhost',
html: './**/*.html',
js: './**/*.js',
}
gulp.task('connect', function() {
connect.server(
{
port: config.port,
base: config.url,
livereload: true
});
});
gulp.task('html', function() {
gulp.src(config.html)
.pipe(connect.reload());
});
gulp.task('js', function() {
gulp.src(config.js)
.pipe(connect.reload());
});
gulp.task('open', ['connect'], function() {
gulp.src('index.html')
.pipe(open({ uri: config.url + ':' + config.port + '/'}));
});
gulp.task('watch', function() {
gulp.watch(config.html, ['html']);
gulp.watch(config.js, ['js' ]);
});
gulp.task('default', ['open','watch']);
{
"name": "myapp",
"version": "1.0.0",
"description": "my app description",
"main": "app.js",
"dependencies": {
"gulp-open": "^2.0.0",
"gulp": "^3.9.1",
"gulp-connect": "^5.0.0"
},
"devDependencies": {},
"author": "your name",
"license": "ISC"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment