-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpfile.js
140 lines (122 loc) · 4.28 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
'use strict';
// Include Gulp and other build automation tools and utilities
// See: https://github.com/gulpjs/gulp/blob/master/docs/API.md
var gulp = require('gulp');
var $ = require('gulp-load-plugins')();
var es = require('event-stream');
var path = require('path');
var runSequence = require('run-sequence');
var webpack = require('webpack');
var fileinclude = require('gulp-file-include');
var rename = require('gulp-rename');
var url = require('url');
var settings = require('./config/settings.js');
var argv = require('minimist')(process.argv.slice(2));
var sass = require('gulp-sass');
var prefix = require('gulp-autoprefixer');
// Settings
var release = argv.release;
var outputPath = release ? settings.prodOutput : settings.devOutput;
var webpackConfig = require('./config/webpack.config.js')(release);
// Node.js runtime dependencies and their version numbers
var pkgs = require('./package.json').dependencies;
Object.keys(pkgs).forEach(function (key) { return pkgs[key] = pkgs[key].substring(1); });
// Clean up
// -----------------------------------------------------------------------------
gulp.task('clean', function(cb){
if(release){
var rimraf = require('rimraf');
rimraf(outputPath, cb);
}
});
// Copy vendor files
// -----------------------------------------------------------------------------
gulp.task('vendor', function(){
return es.merge(
gulp.src('./node_modules/bootstrap-sass/assets/fonts/**')
.pipe(gulp.dest(outputPath + '/fonts')),
gulp.src('./node_modules/font-awesome/fonts/**')
.pipe(gulp.dest(outputPath + '/fonts'))
);
});
// Copy static files / assets
// -----------------------------------------------------------------------------
gulp.task('assets', function(){
return es.merge(
gulp.src('./app/images/**')
.pipe(gulp.dest(outputPath + '/images/')),
gulp.src('./app/styles/fonts/**')
.pipe(gulp.dest(outputPath + '/css/fonts/'))
);
});
// Compile html
// -----------------------------------------------------------------------------
gulp.task('tpl', function(){
return gulp.src('./app/**/*.tpl.html')
.pipe(fileinclude())
.pipe(rename({
extname: ""
}))
.pipe(rename({
extname: ".html"
}))
.pipe(!release ? $.util.noop() : $.htmlmin({
removeComments: true,
collapseWhitespace: true,
minifyJS: true
}))
.pipe(gulp.dest(outputPath));
});
// Copy html files
// -----------------------------------------------------------------------------
gulp.task('html', function(){
return gulp.src('./app/**/*.html')
.pipe(!release ? $.util.noop() : $.htmlmin({
removeComments: true,
collapseWhitespace: true,
minifyJS: true
}))
.pipe(gulp.dest(outputPath));
});
// Copy other files
// -----------------------------------------------------------------------------
gulp.task('approot', function(){
return gulp.src('./app/**/*')
.pipe(!release ? $.util.noop() : $.htmlmin({
removeComments: true,
collapseWhitespace: true,
minifyJS: true
}))
.pipe(gulp.dest(outputPath));
});
// CSS stylesheets
// -----------------------------------------------------------------------------
gulp.task('styles', function(){
return gulp.src('./app/styles/*.scss')
.pipe($.plumber())
.pipe(sass({sourceMap: 'sass', sourceComments: 'map'}))
.pipe($.autoprefixer({browsers: AUTOPREFIXER_BROWSERS}))
.on('error', $.util.log)
.pipe(release ? $.minifyCss() : $.util.noop())
.pipe(gulp.dest(outputPath + '/css'));
});
// Create JavaScript bundle
// -----------------------------------------------------------------------------
gulp.task('javascript', function(cb){
var bundler = webpack(webpackConfig);
function bundle(err, stats){
if (err){
throw new $.util.PluginError('webpack', err);
}
$.util.log('[webpack]', stats.toString({colors: true}));
return cb();
}
bundler.run(bundle);
});
// Build the app from source code
// -----------------------------------------------------------------------------
gulp.task('build', ['clean'], function(cb){
runSequence(['vendor', 'assets', 'styles', 'javascript', 'tpl', 'html', 'approot'], cb);
});
// The default task
gulp.task('default', ['hot']);