2015-05-26 19:16:30 +02:00
|
|
|
var gulp = require('gulp');
|
|
|
|
var gulpif = require('gulp-if');
|
|
|
|
var sourcemaps = require('gulp-sourcemaps');
|
|
|
|
var util = require('gulp-util');
|
|
|
|
var source = require('vinyl-source-stream');
|
|
|
|
var buffer = require('vinyl-buffer');
|
|
|
|
var watchify = require('watchify');
|
|
|
|
var browserify = require('browserify');
|
|
|
|
var browserSync = require('browser-sync');
|
|
|
|
var babelify = require('babelify');
|
|
|
|
var notify = require('gulp-notify');
|
2015-05-29 11:45:10 +02:00
|
|
|
var sass = require('gulp-sass');
|
|
|
|
var concat = require('gulp-concat');
|
2015-05-26 19:16:30 +02:00
|
|
|
var _ = require('lodash');
|
2015-05-29 13:38:59 +02:00
|
|
|
|
|
|
|
var config = {
|
2015-05-29 14:00:09 +02:00
|
|
|
bootstrapDir: './node_modules/bootstrap-sass'
|
2015-05-29 13:38:59 +02:00
|
|
|
};
|
|
|
|
|
2015-05-26 19:16:30 +02:00
|
|
|
gulp.task('build', function() {
|
|
|
|
bundle(false);
|
|
|
|
});
|
|
|
|
|
2015-05-29 14:00:09 +02:00
|
|
|
gulp.task('serve', ['browser-sync', 'sass', 'sass:watch', 'copy'], function() {
|
2015-05-26 19:16:30 +02:00
|
|
|
bundle(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('browser-sync', function() {
|
|
|
|
browserSync({
|
|
|
|
server: {
|
|
|
|
baseDir: "."
|
|
|
|
},
|
|
|
|
port: process.env.PORT || 3000
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2015-05-29 11:45:10 +02:00
|
|
|
gulp.task('sass', function () {
|
|
|
|
gulp.src('./sass/**/main.scss')
|
|
|
|
.pipe(sourcemaps.init())
|
2015-05-29 13:38:59 +02:00
|
|
|
.pipe(sass({
|
|
|
|
includePaths: [
|
|
|
|
config.bootstrapDir + '/assets/stylesheets'
|
|
|
|
]
|
|
|
|
}).on('error', sass.logError))
|
2015-05-29 11:45:10 +02:00
|
|
|
.pipe(sourcemaps.write('./maps'))
|
2015-05-29 14:00:09 +02:00
|
|
|
.pipe(gulp.dest('./build/css'))
|
2015-05-29 12:08:26 +02:00
|
|
|
.pipe(browserSync.stream());;
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task('sass:watch', function () {
|
2015-05-29 13:38:59 +02:00
|
|
|
gulp.watch('./sass/**/*.scss', ['sass']);
|
2015-05-29 11:45:10 +02:00
|
|
|
});
|
|
|
|
|
2015-05-29 11:57:24 +02:00
|
|
|
gulp.task('copy', function () {
|
2015-05-29 14:00:09 +02:00
|
|
|
var files = [
|
2015-05-29 11:57:24 +02:00
|
|
|
'./fonts/**/*',
|
2015-05-29 13:38:59 +02:00
|
|
|
'./img/**/*'
|
2015-05-29 11:57:24 +02:00
|
|
|
];
|
|
|
|
|
2015-05-29 14:00:09 +02:00
|
|
|
gulp.src(files, {base: './'})
|
|
|
|
.pipe(gulp.dest('build'));
|
2015-05-29 13:38:59 +02:00
|
|
|
|
|
|
|
gulp.src(config.bootstrapDir + '/assets/fonts/**/*')
|
2015-05-29 14:00:09 +02:00
|
|
|
.pipe(gulp.dest('./build/fonts'));
|
2015-05-29 11:57:24 +02:00
|
|
|
});
|
|
|
|
|
2015-05-26 19:16:30 +02:00
|
|
|
function bundle(watch) {
|
|
|
|
var bro;
|
|
|
|
|
|
|
|
if (watch) {
|
|
|
|
bro = watchify(browserify('./js/app.js',
|
|
|
|
// Assigning debug to have sourcemaps
|
|
|
|
_.assign(watchify.args, {
|
|
|
|
debug: true
|
|
|
|
})));
|
|
|
|
bro.on('update', function() {
|
|
|
|
rebundle(bro, true);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
bro = browserify('./js/app.js', {
|
|
|
|
debug: true
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bro.transform(babelify.configure({
|
|
|
|
compact: false
|
|
|
|
}));
|
|
|
|
|
|
|
|
function rebundle(bundler, watch) {
|
|
|
|
return bundler.bundle()
|
|
|
|
.on('error', notify.onError('Error: <%= error.message %>'))
|
|
|
|
.pipe(source('app.js'))
|
|
|
|
.pipe(buffer())
|
|
|
|
.pipe(sourcemaps.init({
|
|
|
|
loadMaps: true
|
|
|
|
})) // loads map from browserify file
|
|
|
|
.pipe(sourcemaps.write()) // writes .map file
|
2015-05-29 14:00:09 +02:00
|
|
|
.pipe(gulp.dest('./build'))
|
2015-05-26 19:16:30 +02:00
|
|
|
.pipe(browserSync.stream());
|
|
|
|
}
|
|
|
|
|
|
|
|
return rebundle(bro);
|
|
|
|
}
|