Skip to content

Instantly share code, notes, and snippets.

@pradeep1991singh
Last active February 11, 2017 14:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pradeep1991singh/abf94061b6c32f46c44119f251934058 to your computer and use it in GitHub Desktop.
Save pradeep1991singh/abf94061b6c32f46c44119f251934058 to your computer and use it in GitHub Desktop.
gulp file for html-sass project
'use strict';
var gulp = require('gulp');
var sass = require('gulp-sass');
var naturalSort = require("gulp-natural-sort");
var inject = require('gulp-inject');
var webserver = require('gulp-webserver');
var runSequence = require('run-sequence');
var appBaseUrl = 'http://localhost:8000/index.html';
gulp.task('sass', function () {
return gulp.src('./sass/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./css'));
});
gulp.task('sass:watch', function () {
gulp.watch('./sass/**/*.scss', ['sass']);
});
gulp.task('inject', function () {
var target = gulp.src('./index.html');
// It's not necessary to read the files (will speed up things), we're only after their paths:
var sources = gulp
.src(['./css/**/*.css'
], {
read: false
})
.pipe(naturalSort());
return target
.pipe(inject(sources))
.pipe(gulp.dest('.'));
});
gulp.task('webserver', function() {
gulp.src('.')
.pipe(webserver({
livereload: true,
directoryListing: true,
open: appBaseUrl
}));
});
gulp.task('default', function() {
runSequence('serve');
});
gulp.task('serve', function() {
runSequence('sass', 'inject', 'webserver', 'sass:watch');
});
gulp.task('prod', function() {
runSequence('sass', 'inject');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment