Last active
August 29, 2015 14:20
-
-
Save atabel/cedb32c71119a6a70c1f to your computer and use it in GitHub Desktop.
Gulp bootstrap: amd & livereload
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var gulp = require('gulp'); | |
var amdOptimize = require('amd-optimize'); | |
var concat = require('gulp-concat'); | |
var uglify = require('gulp-uglify'); | |
var sourcemaps = require('gulp-sourcemaps'); | |
var del = require('del'); | |
var minifyHtml = require('gulp-minify-html'); | |
var livereload = require('gulp-livereload'); | |
var http = require('http'); | |
var st = require('st'); | |
var open = require('open'); | |
var paths = { | |
build: 'dist', | |
scripts: 'src/js/**/*.js', | |
html: 'src/**/*.html' | |
}; | |
gulp.task('clean', function (cb) { | |
del([paths.build], cb); | |
}); | |
gulp.task('scripts', function () { | |
gulp.src(paths.scripts) | |
.pipe(sourcemaps.init()) | |
// Traces all modules and outputs them in the correct order. | |
.pipe(amdOptimize('main')) | |
.pipe(concat('build.js')) | |
.pipe(uglify()) | |
.pipe(sourcemaps.write()) | |
.pipe(gulp.dest(paths.build)) | |
.pipe(livereload()); | |
gulp.src(require.resolve('almond')) | |
.pipe(uglify()) | |
.pipe(gulp.dest(paths.build)); | |
}); | |
gulp.task('html', function () { | |
return gulp.src(paths.html) | |
.pipe(minifyHtml()) | |
.pipe(gulp.dest(paths.build)) | |
.pipe(livereload()); | |
}); | |
gulp.task('watch', ['server'], function () { | |
livereload.listen({basePath: paths.build}); | |
gulp.watch(paths.scripts, ['scripts']); | |
gulp.watch(paths.html, ['html']); | |
}); | |
gulp.task('server', function (done) { | |
http.createServer( | |
st({path: __dirname + '/' + paths.build, index: 'index.html', cache: false}) | |
).listen(8080, done); | |
open('http://localhost:8080'); | |
}); | |
gulp.task('default', ['scripts', 'html', 'watch']); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "project-name", | |
"version": "1.0.0", | |
"description": "", | |
"main": "index.js", | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"license": "MIT", | |
"devDependencies": { | |
"amd-optimize": "^0.4.3", | |
"del": "^1.1.1", | |
"gulp": "^3.8.11", | |
"gulp-concat": "^2.5.2", | |
"gulp-livereload": "^3.8.0", | |
"gulp-minify-html": "^1.0.2", | |
"gulp-sourcemaps": "^1.5.2", | |
"gulp-uglify": "^1.2.0", | |
"http": "0.0.0", | |
"open": "0.0.5", | |
"st": "^0.5.3" | |
}, | |
"dependencies": { | |
"almond": "^0.3.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment