-
-
Save paolobueno/0715479c3a4f7811677b to your computer and use it in GitHub Desktop.
Gulp recipe: Jade, Sass, Livereload and static server
This file contains hidden or 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
| node_modules | |
| dist/ |
This file contains hidden or 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'), | |
| gutil = require('gulp-util'), | |
| sass = require('gulp-sass'), | |
| csso = require('gulp-csso'), | |
| uglify = require('gulp-uglify'), | |
| jade = require('gulp-jade'), | |
| concat = require('gulp-concat'), | |
| livereload = require('gulp-livereload'), // Livereload plugin needed: https://chrome.google.com/webstore/detail/livereload/jnihajbhpnppcggbcgedagnkighmdlei | |
| tinylr = require('tiny-lr'), | |
| express = require('express'), | |
| app = express(), | |
| marked = require('marked'), // For :markdown filter in jade | |
| path = require('path'), | |
| server = tinylr(); | |
| var srcDir = './src/'; | |
| var assetDir = path.join(srcDir, 'assets/'); | |
| var distDir = './dist/'; | |
| function assetPath (subpath) { | |
| if (!subpath) return srcDir; | |
| return path.join(assetDir, subpath); | |
| } | |
| function distPath (subpath) { | |
| if (!subpath) return distDir; | |
| return path.join(distDir, subpath); | |
| } | |
| // --- Basic Tasks --- | |
| gulp.task('css', function() { | |
| return gulp.src(assetPath('stylesheets/*.scss')) | |
| .pipe( | |
| sass( { | |
| includePaths: [assetPath('stylesheets')], | |
| errLogToConsole: true | |
| } ) ) | |
| .pipe( csso() ) | |
| .pipe( gulp.dest(distPath('assets/stylesheets/')) ) | |
| .pipe( livereload( server )); | |
| }); | |
| gulp.task('js', function() { | |
| return gulp.src(assetPath('scripts/*.js')) | |
| .pipe( uglify() ) | |
| .pipe( concat('all.min.js')) | |
| .pipe( gulp.dest(distPath('assets/scripts/'))) | |
| .pipe( livereload( server )); | |
| }); | |
| gulp.task('templates', function() { | |
| return gulp.src(path.join(srcDir, '*.jade')) | |
| .pipe(jade({ | |
| pretty: true | |
| })) | |
| .pipe(gulp.dest(distPath())) | |
| .pipe( livereload( server )); | |
| }); | |
| gulp.task('express', function() { | |
| app.use(express.static(path.resolve(distPath()))); | |
| app.listen(1337); | |
| gutil.log('Listening on port: 1337'); | |
| }); | |
| gulp.task('watch', function () { | |
| server.listen(35729, function (err) { | |
| if (err) { | |
| return console.log(err); | |
| } | |
| gulp.watch(assetPath('stylesheets/*.scss'),['css']); | |
| gulp.watch(assetPath('js/*.js'),['js']); | |
| gulp.watch(path.join(srcDir, '*.jade'), ['templates']); | |
| }); | |
| }); | |
| // Default Task | |
| gulp.task('default', ['js','css','templates','express','watch']); |
This file contains hidden or 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": "gulp", | |
| "version": "0.0.1", | |
| "description": "Gulp Recipe - Jade, Sass, Livereload and static server", | |
| "author": "Chris Kjaer", | |
| "devDependencies": { | |
| "gulp-concat": "*", | |
| "gulp-util": "*", | |
| "gulp": "*", | |
| "gulp-uglify": "*", | |
| "gulp-csso": "*", | |
| "gulp-sass": "*", | |
| "gulp-jade": "*", | |
| "gulp-livereload": "*", | |
| "tiny-lr": "*", | |
| "express": "*", | |
| "marked": "*" | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment