Skip to content

Instantly share code, notes, and snippets.

@PAEz
Created March 1, 2016 10:47
Show Gist options
  • Save PAEz/4cd7c8e8ef5ff9e1cf67 to your computer and use it in GitHub Desktop.
Save PAEz/4cd7c8e8ef5ff9e1cf67 to your computer and use it in GitHub Desktop.
Simple script for scss/es6/haml. So I can do codepen like stuff offline. Pretty simple, needs some work, but meh, works for me ;p
// https://community.nitrous.io/tutorials/setting-up-gulp-with-livereload-sass-and-other-tasks
// Paths
var paths = {
scripts: ['src/*.es6'],
sass: ['src/*.scss'],
haml: ['src/index.haml'],
body: ['src/body.haml'],
dest: 'build'
};
var gulp = require('gulp');
var autoprefixer = require('gulp-autoprefixer');
var minifycss = require('gulp-minify-css');
var rename = require('gulp-rename');
var notify = require('gulp-notify');
var babel = require('gulp-babel');
var haml = require('gulp-ruby-haml');
var gulpSass = require('gulp-sass');
var sass = require('node-sass');
var notify = require('node-notifier').Growl;
var notifier = new notify();
var sassOptions = {
functions: {
'pow($a, $b)': function (factor, size) {
return new sass.types.Number(Math.pow(factor.getValue(), size.getValue()) , factor.getUnit());
}
}
};
// Sass
gulp.task('styles', function () {
gulp.src(paths.sass)
.pipe(gulpSass(sassOptions).on('error', function (e) {
notifier.notify({
title: 'SASS',
message: e.message,
sticky: true
});
}))
.pipe(gulp.dest(paths.dest));
});
// // Javascript
gulp.task('javascript', function () {
gulp.src(paths.scripts)
.pipe(babel().on('error', function (e) {
notifier.notify({
title: 'JS',
message: e.message,
sticky: true
});
}))
.pipe(gulp.dest(paths.dest));
// .pipe(notify('Bundling done.'));
});
// // HTML
gulp.task('haml', function () {
gulp.src(paths.haml)
.pipe(haml().on('error', function (e) {
notifier.notify({
title: 'HAML Error',
message: e.message,
sticky: true
});
}))
.pipe(gulp.dest(paths.dest));
});
gulp.task('express', function () {
var express = require('express');
var app = express();
app.use(require('connect-livereload')({
port: 35729
}));
app.use(express.static(paths.dest));
app.listen(4000, '127.0.0.1');
});
var tinylr;
gulp.task('livereload', function () {
tinylr = require('tiny-lr')();
tinylr.listen(35729);
});
function notifyLiveReload (event) {
var fileName = require('path').relative(__dirname, event.path);
tinylr.changed({
body: {
files: [fileName]
}
});
}
gulp.task('watch', function () {
gulp.watch(paths.sass, ['styles']);
gulp.watch(paths.scripts, ['javascript']);
gulp.watch(paths.haml.concat('src/body.haml'), ['haml']);
// gulp.watch([paths.sass, paths.scripts, paths.haml, paths.body], ['haml', 'javascript', 'styles']);
gulp.watch('build/*.html', notifyLiveReload);
gulp.watch('build/*.css', notifyLiveReload);
gulp.watch('build/*.js', notifyLiveReload);
});
gulp.task('default', [ 'styles', 'javascript', 'haml', 'express', 'livereload', 'watch'], function () {});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment