-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
executable file
·91 lines (83 loc) · 2.54 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
/* jshint node: true */
const
gulp = require('gulp'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
mainBowerFiles = require('main-bower-files'),
cleanCSS = require('gulp-clean-css'),
sourcemaps = require('gulp-sourcemaps'),
postcss = require('gulp-postcss'),
inlinesource = require('gulp-inline-source'),
autoprefixer = require('autoprefixer'),
order = require("gulp-order"),
print = require('gulp-print'),
htmlmin = require('gulp-htmlmin')
browserSync = require('browser-sync').create(),
reload = browserSync.reload,
flatten = require('gulp-flatten'),
doiuse = require('doiuse'),
processors = [autoprefixer(), doiuse({
browsers: [
'> 5% in US'
],
ignore: ['flexbox', 'viewport-units'],
ignoreFiles: ['**/*/normalize.css']
})],
historyApiFallback = require('connect-history-api-fallback');
gulp.task('server', function() {
browserSync.init({
notify: false,
server: {
baseDir: "./",
middleware: [historyApiFallback()]
}
});
});
gulp.task('css', function(done) {
return gulp.src(mainBowerFiles('**/*.css').concat(['./src/styles.css']))
.pipe(order([
'**/normalize.css', '**/.css'
]))
.pipe(cleanCSS())
.pipe(postcss(processors))
.pipe(concat('css.css'))
.pipe(gulp.dest('./src/css'))
done();
});
gulp.task('projectCss', function(done) {
return gulp.src('./src/projects.css')
.pipe(cleanCSS())
.pipe(postcss(processors))
.pipe(gulp.dest('./src/css'))
done();
});
gulp.task('js', function() {
return gulp.src('./src/**/*.js')
.pipe(order([
"**/jquery3.js", "**/app.js", "**/*.js"
]))
.pipe(flatten())
.pipe(sourcemaps.init())
.pipe(uglify())
.pipe(concat('js.min.js'))
.pipe(sourcemaps.write('/maps'))
.pipe(gulp.dest('./dist/js'))
.on('end', reload);
});
gulp.task('html', ['css', 'projectCss'], function() {
return gulp.src('./src/**/*.html')
.pipe(flatten())
.pipe(inlinesource())
.pipe(htmlmin({
collapseWhitespace: true,
minifyCSS: true,
minifyJS: true
}))
.pipe(gulp.dest('./'))
.on('end', reload);
});
gulp.task('watch', function() {
gulp.watch('./src/**/*.js', ['js']);
gulp.watch(['./src/**/*.html', './src/**/*.css'], ['html']);
});
gulp.task('default', ['watch', 'html', 'js', 'server', 'projectCss']);