-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
143 lines (129 loc) · 3.99 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
var gulp = require('gulp'),
plumber = require('gulp-plumber'),
rename = require('gulp-rename'),
autoprefixer = require('gulp-autoprefixer');
babel = require('gulp-babel'),
bower = require('gulp-bower');
concat = require('gulp-concat'),
jshint = require('gulp-jshint'),
uglify = require('gulp-uglify'),
imagemin = require('gulp-imagemin'),
rm = require('gulp-rm');
cache = require('gulp-cache'),
minifycss = require('gulp-minify-css'),
mqpacker = require('css-mqpacker'),
csswring = require('csswring'),
postcss = require('gulp-postcss'),
sourcemaps = require('gulp-sourcemaps'),
sass = require('gulp-sass'),
browserSync = require('browser-sync'),
wiredep = require('wiredep').stream,
useref = require('gulp-useref'),
filter = require('gulp-filter'),
inject = require('gulp-inject');
var config = {
prodDir: 'build'
}
gulp.task('clean', function() {
return gulp.src(config.prodDir + '/**/*', {read: false})
.pipe(rm());
})
gulp.task('copy-index', function() {
gulp.src('src/index.html')
.pipe(gulp.dest(config.prodDir))
.pipe(browserSync.reload({stream: true}));
});
gulp.task('bower', function () {
return gulp.src('src/*.html')
.pipe(wiredep({
directory: 'src/bower_components'
}))
.pipe(gulp.dest('config.prodDir'))
.pipe(reload({stream:true}))
});
gulp.task('inject', function(){
return gulp.src(config.prodDir + '/index.html')
.pipe(gulp.src([config.prodDir + '/styles/**',config.prodDir + '/scripts/**'],
{read: false}), {ignorePath: config.prodDir + '/', addRootSlash: false})
.pipe(gulp.dest(config.prodDir))
.pipe(reload({stream:true}));
});
gulp.task('useref', function () {
var jsFilter = filter('**/*.js');
var cssFilter = filter('**/*.css');
// @TODO fix files injection
// return gulp.src('app/*.html')
// .pipe($.useref.assets())
// .pipe(jsFilter)
// .pipe($.ngmin())
// .pipe($.uglify())
// .pipe(jsFilter.restore())
// .pipe(cssFilter)
// .pipe($.csso())
// .pipe(cssFilter.restore())
// .pipe($.useref.restore())
// .pipe($.useref())
// .pipe(gulp.dest('./build'))
});
gulp.task('browser-sync', function() {
browserSync({
server: {
baseDir: config.prodDir
}
});
});
gulp.task('bs-reload', function () {
browserSync.reload();
});
gulp.task('images', function(){
gulp.src('src/images/**/*')
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest('dist/images/'));
});
gulp.task('styles', function(){
var processors = [
// autoprefixer({browsers: ['last 2 version']}),
mqpacker
];
gulp.src(['src/styles/**/*.scss'])
.pipe(plumber({
errorHandler: function (error) {
console.log(error.message);
this.emit('end');
}}))
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sass())
.pipe(postcss(processors))
.pipe(gulp.dest(config.prodDir + '/styles/'))
.pipe(rename({suffix: '.min'}))
.pipe(minifycss())
.pipe(sourcemaps.write('/'))
.pipe(gulp.dest(config.prodDir + '/styles/'))
.pipe(browserSync.reload({stream:true}))
});
gulp.task('scripts', function(){
return gulp.src('src/scripts/**/*.js')
.pipe(plumber({
errorHandler: function (error) {
console.log(error.message);
this.emit('end');
}}))
.pipe(jshint())
.pipe(jshint.reporter('default'))
.pipe(concat('app.js'))
.pipe(babel())
.pipe(gulp.dest(config.prodDir + '/scripts/'))
.pipe(rename({suffix: '.min'}))
.pipe(uglify())
.pipe(gulp.dest(config.prodDir + '/scripts/'))
.pipe(browserSync.reload({stream:true}))
});
gulp.task('watch-files', function() {
gulp.watch('src/index.html', ['copy-index']);
gulp.watch('bower.json', ['bower']);
gulp.watch("src/styles/**/*.scss", ['styles']);
gulp.watch("src/scripts/**/*.js", ['scripts']);
gulp.watch("*.html", ['bs-reload']);
})
gulp.task('pre-compile', ['clean', 'copy-index', 'bower', 'styles', 'scripts'])
gulp.task('default', ['pre-compile', 'browser-sync', 'watch-files']);