This repository has been archived by the owner on May 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
139 lines (120 loc) · 3.37 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
var gulp = require('gulp'),
bs = require('browser-sync').create(),
htmlmin = require('gulp-htmlmin'),
babel = require('gulp-babel'),
concat = require('gulp-concat'),
uglify = require('gulp-uglifyjs'),
sass = require('gulp-sass'),
imagemin = require('gulp-imagemin'),
zip = require('gulp-zip');
sourcemaps = require('gulp-sourcemaps'),
historyApiFallback = require('connect-history-api-fallback');
/*
* @param {string} name
* @param {Array|string} dependencies
*/
function addWatcher(name, dependencies) {
return gulp.task(name + '-watch', dependencies, function(done) { bs.reload(); done(); });
}
gulp.task('html', function() {
gulp.src('./source/**/*.html')
.pipe(htmlmin({
collapseWhitespace: false,
removeComments: false
}))
.pipe(gulp.dest('./public'));
});
gulp.task('html-prod', function() {
gulp.src('./source/**/*.html')
.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true
}))
.pipe(gulp.dest('./build'));
});
gulp.task('js', function() {
gulp.src('./source/js/**/*.js')
.pipe(sourcemaps.init())
.pipe(concat('app.bundle.js'))
.pipe(babel({
presets: ['es2015']
}))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./public/js'));
});
gulp.task('js-prod', function() {
gulp.src('./source/js/**/*.js')
.pipe(concat('app.bundle.js'))
.pipe(babel({
presets: ['es2015']
}))
.pipe(uglify())
.pipe(gulp.dest('./build/js'));
});
gulp.task('sass', function() {
gulp.src('./source/styles/**/*.scss')
.pipe(sourcemaps.init())
.pipe(sass({
outputStyle: 'expanded' // nested, expanded, compact, compressed
}).on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(gulp.dest('./public/styles'));
});
gulp.task('sass-prod', function() {
gulp.src('./source/styles/**/*.scss')
.pipe(sass({
outputStyle: 'compressed' // nested, expanded, compact, compressed
}).on('error', sass.logError))
.pipe(gulp.dest('./build/styles'));
});
gulp.task('assetsmin', function() {
gulp.src('./source/assets/**/*')
.pipe(imagemin())
.pipe(gulp.dest('./public/assets'));
});
gulp.task('assetsmin-prod', function() {
gulp.src('./source/assets/**/*')
.pipe(imagemin())
.pipe(gulp.dest('./build/assets'));
});
gulp.task('vendormove', function() {
gulp.src('./source/vendor/**/*')
.pipe(gulp.dest('./public/vendor'));
});
gulp.task('vendormove-prod', function() {
gulp.src('./source/vendor/**/*')
.pipe(gulp.dest('./build/vendor'));
});
gulp.task('json', function() {
gulp.src('./source/**/*.json')
.pipe(gulp.dest('./public'));
});
gulp.task('json-prod', function() {
gulp.src('./source/**/*.json')
.pipe(gulp.dest('./build'));
});
addWatcher('html', ['html']);
addWatcher('js', ['js']);
addWatcher('sass', ['sass']);
addWatcher('json', ['json']);
gulp.task('serve', ['html', 'js', 'sass', 'assetsmin', 'vendormove', 'json'], function() {
bs.init({
server: {
baseDir: './public',
middleware: [historyApiFallback()]
},
notify: false
});
gulp.watch('./source/**/*.html', ['html-watch']);
gulp.watch('./source/js/**/*.js', ['js-watch']);
gulp.watch('./source/styles/**/*.scss', ['sass-watch']);
gulp.watch('./source/**/*.json', ['json-watch']);
});
gulp.task('default', ['serve']);
gulp.task('build-dev');
gulp.task('build-prod', ['html-prod', 'js-prod', 'sass-prod', 'vendormove-prod', 'json-prod']);
gulp.task('pack', function() {
gulp.src('./build/**/*')
.pipe(zip('app.pack.zip'))
.pipe(gulp.dest('./'));
});