Skip to content

Instantly share code, notes, and snippets.

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 totora0155/904fc4ea80ee6674bf11 to your computer and use it in GitHub Desktop.
Save totora0155/904fc4ea80ee6674bf11 to your computer and use it in GitHub Desktop.
'use strict';
var $, $$, browserSync, del, getTypeName, makeCompileStream, paths, reload, runSequence, use;
$$ = require('gulp');
$ = require('gulp-load-plugins')();
runSequence = require('run-sequence');
del = require('del');
browserSync = require('browser-sync');
reload = browserSync.reload;
paths = {
html: 'app/**/*.html',
sass: 'app/style/**/*.scss',
less: 'app/style/**/*.less',
stylus: 'app/style/**/*.styl',
coffee: 'app/script/**/*.coffee',
dist: 'app/**/*.{html,css,js,map}'
};
use = {
sass: 'rubySass',
less: 'less',
stylus: 'stylus',
coffee: 'coffee'
};
getTypeName = function(path) {
if (path.indexOf('style') > -1) {
return 'style';
}
if (path.indexOf('script') > -1) {
return 'script';
}
return console.error(new Error('Invalid type'));
};
makeCompileStream = function(lang, path, opts) {
var compiler, typeName;
typeName = getTypeName(path);
compiler = $[use[lang]];
return $$.src(path).pipe($.plumber()).pipe($.cached(lang)).pipe($.sourcemaps.init()).pipe($["if"]('*.coffee', $.coffeelint())).pipe($["if"]('*.coffee', $.coffeelint.reporter())).pipe(compiler(opts)).pipe($.sourcemaps.write()).pipe($$.dest("app/" + typeName)).pipe($["if"]('*.css', reload({
stream: true
}), reload())).pipe($.size({
showFile: true,
title: typeName
}));
};
$$.task('del', del.bind(null, ['dist/**/*']));
$$.task('copy', function() {
return $$.src(paths.dist).pipe($["if"]('*.html', $.minifyHtml())).pipe($["if"]('*.css', $.pleeease())).pipe($["if"]('*.js', $.uglify())).pipe($$.dest('dist'));
});
$$.task('sass', function() {
var opts;
opts = {
style: 'expanded',
precision: 10
};
return makeCompileStream('sass', paths.sass, opts);
});
$$.task('less', function() {
var opts;
opts = {};
return makeCompileStream('less', paths.less, opts);
});
$$.task('stylus', function() {
var opts;
opts = {};
return makeCompileStream('stylus', paths.stylus, opts);
});
$$.task('coffee', function() {
var opts;
opts = {};
return makeCompileStream('coffee', paths.coffee, opts);
});
$$.task('default', function() {
browserSync({
server: ['app'],
port: 8000,
notify: false,
open: false
});
$$.watch(paths.html, reload);
$$.watch(paths.sass, ['sass']);
$$.watch(paths.less, ['less']);
$$.watch(paths.stylus, ['stylus']);
return $$.watch(paths.coffee, ['coffee']);
});
$$.task('dist', function(cb) {
return runSequence('del', 'copy', cb);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment