-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
103 lines (95 loc) · 3.03 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
var browserifyBundler, copyResources, buildStyles, buildApp, packageApp,
gulp = require('gulp'),
gulpLoadPlugins = require('gulp-load-plugins'),
$ = gulpLoadPlugins({}),
log = require('color-log'),
source = require('vinyl-source-stream'),
buffer = require('vinyl-buffer'),
watchify = require('watchify'),
browserify = require('browserify'),
runSequence = require('run-sequence'),
brec = require('brec-tables'),
paths = {
app: 'app',
dist: 'dist'
};
/* Browserify bundler */
watchify.args.debug = ($.util.env.type !== 'production');
browserifyBundler = browserify(watchify.args);
/* Empty the paths.dist directory */
gulp.task('clean', function() {
return gulp.src(paths.dist, {read: false})
.pipe($.rimraf());
});
/* Copy all resources to dist */
copyResources = function() {
log.mark('Copying resources...');
return gulp.src([
paths.app + '/**/*.*',
'!' + paths.app + '/**/*.+(js|hbs|scss)',
])
.pipe(gulp.dest(paths.dist));
};
gulp.task('copy-resources', copyResources);
/* Build all styles */
buildStyles = function() {
return gulp.src([paths.app + '/**/*.scss'])
.pipe($.sass({
includePaths: [brec.base.sass, brec.tables.sass],
onSuccess: function(err) {
log.mark('[SUCCESS] {Sass} ' + err.css.length + ' bytes written (' + (err.stats.duration / 1000.0) + ' seconds)');
},
onError: function(err) {
log.error('[ERROR] {Sass} @ ' + (new Date()));
log.warn('Message: ' + err.message);
log.warn('in file --> ' + err.file);
}
}))
.pipe(gulp.dest(paths.dist))
};
gulp.task('build-styles', buildStyles);
/* Reduce all javascript to app.js */
buildApp = function() {
return browserifyBundler.bundle()
.on('error', function(err, b) {
delete err.stream;
log.error('[ERROR] {Browserify} @ ' + (new Date()));
log.warn(err.toString());
return true;
})
.pipe(source('app.js'))
.pipe(buffer())
.pipe($.util.env.type !== 'production' ? $.sourcemaps.init({loadMaps: true}) : $.util.noop())
.pipe($.util.env.type === 'production' ? $.uglify() : $.util.noop())
.pipe($.util.env.type !== 'production' ? $.sourcemaps.write('./') : $.util.noop())
.pipe(gulp.dest(paths.dist));
};
gulp.task('build-app', buildApp);
/* Full build */
gulp.task('build', function(callback) {
browserifyBundler.add('./' + paths.app + '/main');
browserifyBundler.transform('aliasify', {global: true});
browserifyBundler.transform('hbsfy');
runSequence('clean',
[
'copy-resources',
'build-styles',
'build-app'
],
callback);
});
/* Watch build */
gulp.task('watch', function() {
browserifyBundler = watchify(browserifyBundler);
browserifyBundler.on('update', buildApp);
browserifyBundler.on('log', function(err) {
log.mark('[SUCCESS] {Javascript} ' + err.toString());
});
gulp.start('build', function() {
gulp.watch(paths.app + '/**/*.scss', buildStyles);
gulp.watch([
paths.app + '/**/*.*',
'!' + paths.app + '/**/*.+(hbs|js|scss)',
], copyResources);
});
});