-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgulpfile.js
157 lines (139 loc) · 4.25 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
var gulp = require('gulp')
concat = require('gulp-concat')
sourcemaps = require('gulp-sourcemaps')
uglify = require('gulp-uglify')
ngAnnotate = require('gulp-ng-annotate')
connect = require('gulp-connect');
plumber = require( 'gulp-plumber' ),
autoprefixer = require('gulp-autoprefixer'),
watch = require( 'gulp-watch' ),
minifycss = require( 'gulp-minify-css' ),
jshint = require( 'gulp-jshint' ),
stylish = require( 'jshint-stylish' ),
uglify = require( 'gulp-uglify' ),
rename = require( 'gulp-rename' ),
notify = require( 'gulp-notify' ),
include = require( 'gulp-include' ),
sass = require( 'gulp-sass' );
bower = require('gulp-bower');
zip = require('gulp-zip');
wrap = require("gulp-wrap");
// Config
var config = {
bowerDir: './bower_components'
}
// Default error handler
var onError = function( err ) {
console.log( 'An error occured:', err.message );
this.emit('end');
}
// Copy font files
gulp.task('fonts', function() {
return gulp.src(config.bowerDir + '/bootstrap/fonts/**.*')
.pipe(gulp.dest('./fonts'));
});
// Zip up everything
gulp.task('zip', function () {
return gulp.src([
'*',
'./js/**/*',
'./css/*',
'./dist/*',
'./fonts/*',
'./sass/**/*',
'./partials/**/*',
'!bower_components',
'!node_modules',
], {base: "."})
.pipe(zip('ngWP.zip'))
.pipe(gulp.dest('.'));
});
//Concat only bower JS files needed
gulp.task('vendorjs', function() {
return gulp.src([
config.bowerDir + '/angular/angular.min.js',
config.bowerDir + '/angular-animate/angular-animate.min.js',
config.bowerDir + '/angular-bootstrap/ui-bootstrap-tpls.min.js',
config.bowerDir + '/angular-loading-bar/build/loading-bar.min.js',
config.bowerDir + '/angular-sanitize/angular-sanitize.min.js',
config.bowerDir + '/angular-ui-router/release/angular-ui-router.min.js',
config.bowerDir + '/angular-ui-router-title/src/angular-ui-router-title.js',
])
.pipe(concat('vendor.js'))
.pipe(gulp.dest('./dist/'))
.pipe(uglify())
.pipe( rename( { suffix: '.min' } ) )
.pipe( gulp.dest( './dist' ) )
.pipe( notify({ message: 'vendorjs task complete' }))
});
//Concat bower CSS files needed
gulp.task('vendorcss', function() {
return gulp.src([
config.bowerDir + '/bootstrap/dist/css/bootstrap.min.css',
config.bowerDir + '/angular-bootstrap/ui-bootstrap-csp.css',
config.bowerDir + '/angular-loading-bar/build/loading-bar.min.css',
])
.pipe( concat('vendor.css'))
.pipe( gulp.dest('./dist/'))
.pipe( minifycss())
.pipe( rename( { suffix: '.min' } ) )
.pipe( gulp.dest( './dist' ) )
.pipe( notify({ message: 'vendorcss task complete' }))
});
// Install all Bower components
gulp.task('bower', function() {
return bower()
.pipe(gulp.dest(config.bowerDir))
});
// Concat all the Angular JS files to app.js
gulp.task('js', function () {
gulp.src(['js/**/module.js', 'js/**/*.js'])
.pipe(wrap('(function(){\n"use strict";\n<%= contents %>\n})();'))
.pipe(sourcemaps.init())
.pipe(concat('app.js'))
.pipe(ngAnnotate())
.pipe(uglify())
.pipe(sourcemaps.write())
.pipe(gulp.dest('.'))
});
//Sass Options
var options = {};
options.sass = {
errLogToConsole: true,
sourceMap: 'sass',
sourceComments: 'map',
precision: 10,
};
options.autoprefixer = {
map: true
};
gulp.task('sass', function() {
return gulp.src('./sass/style.scss')
.pipe( plumber( { errorHandler: onError } ) )
.pipe(sass(options.sass))
.pipe(autoprefixer('last 2 version', 'safari 5', 'ios 6', 'android 4',
options.autoprefixer
))
.pipe( gulp.dest( './css' ) )
.pipe( minifycss() )
.pipe( rename( { suffix: '.min' } ) )
.pipe( gulp.dest( './css' ) )
.pipe( notify({ message: 'sass task complete' }))
});
// Start a server
gulp.task('serve', function() {
connect.server({
port: 3000,
fallback: 'index.html',
livereload: true
});
});
// Watch files for change
gulp.task( 'watch', function() {
// don't listen to whole js folder, it'll create an infinite loop
gulp.watch('js/**/*.js', ['js'])
gulp.watch( './sass/**/*.scss', ['sass'] );
} );
gulp.task( 'default', ['watch'], function() {
// Does nothing in this task, just triggers the dependent 'watch'
} );