Skip to content

Instantly share code, notes, and snippets.

@donhenton
Created December 20, 2017 14:15
Show Gist options
  • Save donhenton/33102d201c0949f098ef9835c190a866 to your computer and use it in GitHub Desktop.
Save donhenton/33102d201c0949f098ef9835c190a866 to your computer and use it in GitHub Desktop.
Gulp file using browser sync and sass
/*
package.json
{
"name": "survey-css",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node get a job"
},
"author": "",
"license": "ISC",
"devDependencies": {
"browser-sync": "^2.18.13",
"del": "^2.2.0",
"gulp": "^3.8.11",
"gulp-autoprefixer": "^4.0.0",
"gulp-concat": "^2.6.1",
"gulp-sass": "^2.0.1",
"gulp-sourcemaps": "^2.6.1"
}
}
*/
var gulp = require('gulp');
var targetLocation = './public_html/'
var appDependencies = require('./package.json').dependencies;
var SASS_FILES = [ './src/sass/**/*.scss'];
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var fs = require('fs');
var del = require('del');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');
var concat = require('gulp-concat');
//https://browsersync.io/docs/gulp
gulp.task('clean', function ( ) {
del(['target','public_html/css/style.css']);
});
gulp.task('compile-sass', function() {
return gulp.src('./src/sass/main.scss')
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(autoprefixer({
browsers: ['last 2 versions', 'Explorer 9']
}))
.pipe(sass())
.pipe(concat('style.css'))
// .pipe(uglifycss())
.pipe(gulp.dest('./public_html/css/'))
//.pipe(browsersync.reload({stream: true}));
.pipe(browserSync.stream());
});
gulp.task('serve', ['compile-sass'], function() {
browserSync.init({
server: "./public_html",
port: 6060,
ui: {port: 6061}
});
gulp.watch(SASS_FILES, ['compile-sass'] ) ;
gulp.watch("public_html/*.html").on('change', browserSync.reload);
});
gulp.task('init-dev',[ 'sass-build']);
gulp.task('dev', ['serve']);
/* end frontend task ---------------------------------------- */
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment