-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
113 lines (100 loc) · 3.27 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"use strict";
var gulp = require('gulp');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var autoprefixer = require('gulp-autoprefixer');
var browserSync = require('browser-sync').create('browserSync');
var browserify = require('browserify');
var del = require('del');
var runSequence = require('run-sequence');
var fs = require('fs');
var brfs = require('brfs');
var babel = require('babelify');
var source = require('vinyl-source-stream');
var listImages = require('./gulp/listImages');
var listAudio = require('./gulp/listAudio');
var sourcemaps = require('gulp-sourcemaps');
var environement = {
production: "production",
staging: "staging"
};
var paths = {
HTML: 'src/index.html',
CSS: 'src/css/*.scss',
JS: 'src/**/*.js',
PRODUCTION: 'production/',
STAGING: 'staging/',
ASSETS:'src/assets/**/*.*',
ENTRY_POINT:'src/main.js'
};
var partials = {
ASSETS: '/resources/assets',
RESOURCES: '/resources'
};
// "gulp" : will build to staging, launch browsersync and listen to any new changes.
// "gulp build:production" will build to production.
function createTasks(env, path){
gulp.task('clean:'+env, function(callback){
return del([path + "**/*.*"], callback);
});
gulp.task('handleHTML:'+env, function(){
return gulp.src(paths.HTML)
.pipe(gulp.dest(path))
.pipe(browserSync.stream());
});
gulp.task('handleAssets:'+env, function() {
return gulp.src(paths.ASSETS)
.pipe(gulp.dest(path + partials.ASSETS));
});
gulp.task('handleJS:'+env, function(){
return browserify({
entries: [paths.ENTRY_POINT],
transform: [listImages, listAudio, brfs, babel.configure({
ignore: /libs.+/
})],
debug: env == environement.staging,
cache: {},
packageCache: {},
fullPaths: env == environement.staging
})
.bundle()
.on('error', function(err){
console.log(err.message);
})
.pipe(source("bundle.js"))
.pipe(gulp.dest(path + partials.RESOURCES))
.pipe(browserSync.stream());
});
gulp.task('handleCSS:'+env, function () {
return gulp.src(paths.CSS)
.pipe(sass().on('error', sass.logError))
.pipe(concat("bundle.css"))
.pipe(autoprefixer({
browsers: ['last 2 versions'],
cascade: true
}))
.pipe(gulp.dest(path + partials.RESOURCES))
.pipe(browserSync.stream());
});
gulp.task('build:'+env, function(){
runSequence('clean:'+env, ['handleHTML:'+env, 'handleCSS:'+env, 'handleAssets:'+env, 'handleJS:'+env]);
});
}
createTasks(environement.production, paths.PRODUCTION);
createTasks(environement.staging, paths.STAGING);
gulp.task('default', function(){
runSequence(['build:staging'], ['browser-sync'], ['watch']);
});
gulp.task('browser-sync', function() {
browserSync.init({
server: {
baseDir: paths.STAGING
}
});
});
gulp.task('watch', function(){
gulp.watch(paths.HTML, ['handleHTML:staging']);
gulp.watch(paths.CSS, ['handleCSS:staging']);
gulp.watch(paths.JS, ['handleJS:staging']);
gulp.watch(paths.ASSETS, ['handleAssets:staging']);
});