-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
119 lines (106 loc) · 3.39 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
var gulp = require('gulp'),
gulpPlugins = require('gulp-load-plugins'),
runSequence = require('run-sequence'),
browserSync = require('browser-sync'),
del = require('del'),
path = require('path'),
config = require('./config.json'),
reload = browserSync.reload,
webpack = require('webpack-stream'),
ngAnnotatePlugin = require('ng-annotate-webpack-plugin'),
$ = gulpPlugins(),
AUTOPREFIXER_BROWSERS = [
'ie >= 10',
'ie_mob >= 10',
'ff >= 30',
'chrome >= 34',
'safari >= 7',
'opera >= 23',
'ios >= 7',
'android >= 4.4',
'bb >= 10'
];
gulp.task('build-styles', function() {
return gulp.src(config.projectDirectory + '/' + config.cssRawBundle)
.pipe($.sourcemaps.init({debug: true}))
.pipe($.stylus())
.pipe($.autoprefixer({browsers: AUTOPREFIXER_BROWSERS}))
.pipe($.sourcemaps.write('.'))
.pipe(gulp.dest('.temporal/' + config.cssDirectory));
});
gulp.task('templates', function() {
return gulp.src(config.projectDirectory + '/' + config.jsDirectory + '/**/*.html')
.pipe($.htmlmin({ collapseWhitespace: true }))
.pipe($.ngTemplates({
filename: 'templates.js',
module: 'templates',
standalone: true,
path: function (url) {
return url.replace(path.dirname(url), '.');
}
}))
.pipe(gulp.dest(config.projectDirectory + '/' + config.jsDirectory));
});
gulp.task('build-scripts', [ 'templates' ], function() {
return gulp.src(config.projectDirectory + '/' + config.jsRawBundle)
.pipe(webpack({
output: {
filename: config.jsBundle
},
devtool: 'source-map',
plugins: [
new ngAnnotatePlugin({
add: true
})
]
}))
.pipe(gulp.dest('.temporal/' + config.jsDirectory));
});
function runServer(build) {
var baseDirectories = [ '.temporal', config.projectDirectory ];
if ( build ) {
baseDirectories = [ 'build' ];
}
browserSync({
open: false,
notify: false,
logPrefix: 'Initial Layout',
server: {
baseDir: baseDirectories,
// Middleware for SPA
middleware: function(req, res, next) {
if( config.spa ) {
if(/\S\.{1}(jpg|jpeg|png|svg|css|js|map|ttf|eot|woff|html)/.test(req.url) !== true){
req.url = '/index.html';
}
}
return next();
}
}
});
}
gulp.task('serve', [ 'build-styles', 'build-scripts' ], function() {
runServer();
gulp.watch(config.projectDirectory + '/**/*.html', ['build-scripts', reload]);
gulp.watch(config.projectDirectory + '/**/*.{styl,css}', ['build-styles', reload]);
gulp.watch(config.projectDirectory + '/**/*.js', ['build-scripts',reload]);
gulp.watch(config.projectDirectory + '/**/*.{jpg,jpeg,png,gif}', reload);
});
gulp.task('build', [ 'default', 'build-styles', 'build-scripts' ], function(asd) {
return gulp.src([ '.temporal/**',
config.projectDirectory + '/**',
'!' + config.projectDirectory + '/' + config.cssDirectory + '/**',
'!' + config.projectDirectory + '/' + config.jsDirectory + '/**'
])
.pipe($.if('*.html', $.htmlmin({ collapseWhitespace: true })))
.pipe(gulp.dest('build'))
.pipe($.if('*.css', $.csso() ))
.pipe($.if('*.js', $.uglify() ))
.pipe(gulp.dest('build'));
});
gulp.task('clean', function(){
return del([ 'build/*', '.temporal/*' ]);
});
gulp.task('default', ['clean'], function() {
runSequence( 'build-styles', 'build-scripts' );
});