Skip to content

Instantly share code, notes, and snippets.

@mindvox
Last active April 5, 2016 16:30
Show Gist options
  • Save mindvox/e7e2f6776785646829df to your computer and use it in GitHub Desktop.
Save mindvox/e7e2f6776785646829df to your computer and use it in GitHub Desktop.
Babel Gulpfile
// import dependancies
let config = require('./core/config');
let gulp = require('gulp'),
// styles
less = require('gulp-less'),
cssnano = require('gulp-cssnano'),
// scripts
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
// images
imagemin = require('gulp-imagemin'),
cache = require('gulp-cache'),
// utilities
header = require('gulp-header'),
rename = require('gulp-rename'),
// server
nodemon = require('gulp-nodemon');
// compile stylesheets
gulp.task('build:styles', () => {
return gulp.src(config.build.styles.path + '/index.less')
.pipe(less({ paths: config.build.styles.paths }))
.pipe(gulp.dest('/tmp'))
.pipe(rename({ suffix: '-' + config.build.hash }))
.pipe(cssnano({ discardComments: { removeAll: true } }))
.pipe(header(config.build.banner))
.pipe(gulp.dest(config.build.styles.dest));
});
// compile client-side frameworks
gulp.task('build:frameworks', () => {
return gulp.src(config.build.scripts.frameworks)
.pipe(concat('framework.js'))
.pipe(gulp.dest('tmp/'))
.pipe(rename({suffix: '-' + config.build.hash}))
.pipe(uglify())
.pipe(header(config.build.banner))
.pipe(gulp.dest(config.build.scripts.dest));
});
// compile client-side scripts
gulp.task('build:scripts', () => {
return gulp.src(config.build.scripts.path + '/**/*.js')
.pipe(concat('index.js'))
.pipe(gulp.dest('tmp/'))
.pipe(rename({suffix: '-' + config.build.hash}))
.pipe(uglify())
.pipe(header(config.build.banner))
.pipe(gulp.dest(config.build.scripts.dest));
});
// optimize and move images into public directory
gulp.task('build:images', function() {
return gulp.src(config.build.images.path + '/**/*.{png,jpg}')
.pipe(cache(imagemin({
optimizationLevel: 3,
progressive: true,
interlaced: true
})))
.pipe(gulp.dest(config.build.images.dest));
});
// copy fonts into public directory
gulp.task('build:fonts', () => {
return gulp.src(config.build.fonts.paths)
.pipe(gulp.dest(config.build.fonts.dest));
});
// launch an instance of our application for development
gulp.task('nodemon', () => {
nodemon({
exec: 'npm run start:dev',
ext: 'hbs js',
env: { 'NODE_ENV': 'development' },
ignore: ['./content/scripts', './gulpfile.babel.js']
});
});
// watch files for changes
gulp.task('watch', ['nodemon'], () => {
gulp.watch('./public/lib/**/*.js', ['build:frameworks']);
gulp.watch(config.build.scripts.path + '/**/*.js', ['build:scripts']);
gulp.watch(config.build.styles.path + '/**/*.less', ['build:styles']);
});
// register tasks which will be launched when running `gulp` from the terminal
gulp.task('default', ['build:styles', 'build:frameworks', 'build:scripts', 'build:images', 'build:fonts']);
@mindvox
Copy link
Author

mindvox commented Apr 5, 2016

Naturally you will want to adjust this to work with your directories or whatever. Anyhow, enjoy! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment