-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
156 lines (138 loc) · 4.34 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
//Utilities
var browserSync = require('browser-sync').create();
var sassdoc = require('sassdoc');
//Gulp
var gulp = require('gulp'),
useref = require('gulp-useref');
// Gulp plugins
var sass = require('gulp-sass');
var sourcemaps = require('gulp-sourcemaps');
var autoprefixer = require('gulp-autoprefixer');
var htmlmin = require('gulp-htmlmin');
var uglify = require('gulp-uglify');
var gulpIf = require('gulp-if');
var imagemin = require('gulp-imagemin');
var cache = require('gulp-cache');
var del = require('del');
var cssnano = require('gulp-cssnano');
var runSequence = require('run-sequence');
var UglifyJS = require("uglify-es"); // can be a git checkout
//Task options
var input = 'app/scss/*.scss';
var output = 'app/css';
var autoprefixerOptions = {
browsers: ['last 2 versions', '> 5%', 'Firefox ESR'],
cascade: true
};
var sassOptions = {
errLogToConsole: true,
outputStyle: 'expanded',
includePaths: require('node-normalize-scss').includePaths
};
var sassdocOptions = {
dest: './app/sassdoc'
};
// ----------------------------
// Gulp task definitions
// ----------------------------
gulp.task('sass', function () {
// Find all `.scss` files from the `app/scss/` folder
return gulp.src(input)
//Starts SourceMaps
.pipe(sourcemaps.init())
//Starts Sass and throw an error when something goes wrong
.pipe(sass(sassOptions).on('error', sass.logError))
//Starts autoprefixer with our options
.pipe(autoprefixer(autoprefixerOptions))
//Write our Map file to css final destinations
.pipe(sourcemaps.write("."))
//Write our destinations files
.pipe(gulp.dest(output))
//Refresh the browser
.pipe(browserSync.stream());
});
gulp.task('sassdoc', function () {
// Release the docs! gulp sassdoc
return gulp
.src(input)
.pipe(sassdoc(sassdocOptions))
.resume();
});
gulp.task('watch', ['sass'], function () {
browserSync.init({
server: "./app"
});
// Watch the input folder for change,
// and run `sass` task when something happens
gulp.watch(input, ['sass'])
gulp.watch(["app/*.html", "app/js/*.js"]).on('change', browserSync.reload)
});
gulp.task('fonts', function () {
return gulp.src('app/fonts/**/*')
.pipe(gulp.dest('dist/fonts'))
});
gulp.task('json', function () {
return gulp.src('app/json/**/*')
.pipe(gulp.dest('dist/json'))
});
/*gulp.task('svg', function () {
return gulp.src('app/img/')
.pipe(gulp.dest('dist/img'))
});*/
gulp.task('images', function () {
return gulp.src('./app/img/**/*.+(png|jpg|jpeg|gif|svg)')
// Not Caching images that ran through imagemin
.pipe(imagemin({
interlaced: true
}))
.pipe(gulp.dest('./dist/img'))
});
/*
PENDING CACHE, CHECK VERSIONS, UPDATE GULP-CACHE
.pipe(cache(imagemin({
interlaced: true
})))
*/
gulp.task('clean:dist', function () {
return del.sync('dist');
})
gulp.task('cache:clear', function (callback) {
return cache.clearAll(callback)
})
gulp.task('useref', function () {
return gulp.src('app/index.html')
.pipe(useref())
// Minifies only if it's a JavaScript file
// .pipe(gulpIf('*.js', uglify().on('error', function(e){
// console.log(e);
// })))
// Minifies only if it's a CSS file
.pipe(gulpIf('*.css', cssnano()))
.pipe(gulp.dest('dist'))
});
gulp.task('userefscripts', ['clean'], function () {
return gulp.src('js/*.js')
.pipe(uglify().on('error', function(e){
console.log(e);
}))
.pipe(gulp.dest('minjs'));
});
/* PENDING INTEGRATE MINIFY INDEX TO PRODUCTION */
gulp.task('minifyIndex', function () {
return gulp.src('dist/index.html')
.pipe(htmlmin({
collapseWhitespace: true
}))
.pipe(gulp.dest('./dist'));
});
gulp.task('prod', function (callback) {
runSequence('clean:dist', ['json','sassdoc', 'useref', 'images'],
callback
)
})
gulp.task('default', ['sass', 'watch' /*, possible other tasks... */ ]);
gulp.task('defaultTest', function (callback) {
runSequence(['sass', 'browserSync', 'watch'],
callback
)
})