-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·134 lines (120 loc) · 3.12 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
'use strict';
const gulp = require('gulp'),
sass = require('gulp-sass'),
htmlmin = require('gulp-htmlmin'),
uglify = require('gulp-uglify'),
concat = require('gulp-concat'),
minifyCss = require('gulp-minify-css'),
sourcemaps = require('gulp-sourcemaps'),
rename = require('gulp-rename');
const { src, dest, series, watch } = gulp;
var paths = {
moveTemplates: {
src: './src/templates/**/*.html',
dest: './public/templates'
},
moveAssets: {
src: './src/assets/**/*',
dest: './public/assets'
},
sassToCSS: {
src: './src/scss/main.scss',
newName: 'style.css',
dest: './public/css'
},
minifyCSS: {
src: './public/css/style.css',
newName: 'style.min.css',
dest: './public/css'
},
concatJS: {
concat: 'script.js'
},
uglifyJS: {
src: './public/js/script.js',
newName: 'script.min.js'
},
html: {
src: './src/*.html',
dest: 'public'
},
scss: {
src: './src/scss/main.scss',
dest: './public/css',
watch: ['./src/scss/**/*.scss']
},
js: {
src: [
'./node_modules/angular/angular.js',
'./node_modules/angular-ui-router/release/angular-ui-router.js',
'./node_modules/angular-local-storage/dist/angular-local-storage.js',
'./src/js/**/*.js'
],
dest: './public/js/'
}
};
const _moveTemplates = function() {
const { moveTemplates } = paths;
return src(moveTemplates.src)
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(dest(moveTemplates.dest));
};
const _moveAssets = function() {
const { moveAssets } = paths;
return src(moveAssets.src)
.pipe(dest(moveAssets.dest));
};
const _moveHTML = function() {
const { html } = paths;
return src(html.src)
.pipe(dest(html.dest));
};
const _minifyHTML = series(_moveHTML, function() {
const { html } = paths;
return src(html.src)
.pipe(htmlmin({collapseWhitespace: true}))
.pipe(dest(html.dest));
});
const _sassToCSS = function() {
const { sassToCSS } = paths;
return src(sassToCSS.src)
.pipe(sourcemaps.init())
.pipe(sass().on('error', sass.logError))
.pipe(sourcemaps.write())
.pipe(rename(sassToCSS.newName))
.pipe(dest(sassToCSS.dest));
};
const _minifyCSS = series(_sassToCSS, function() {
const { minifyCSS } = paths;
return src(minifyCSS.src)
.pipe(minifyCss())
.pipe(rename(minifyCSS.newName))
.pipe(dest(minifyCSS.dest));
});
const _concatJS = function() {
const { js, concatJS } = paths;
return src(js.src)
// .pipe(sourcemaps.init())
.pipe(concat(concatJS.concat))
// .pipe(sourcemaps.write())
.pipe(dest(js.dest));
};
const _uglifyJS = series(_concatJS, function() {
const { uglifyJS, js } = paths;
return src(uglifyJS.src)
.pipe(uglify())
.pipe(rename(uglifyJS.newName))
.pipe(dest(js.dest));
});
const dev = function() {
watch(paths.moveTemplates.src, {ignoreInitial: false}, _moveTemplates);
watch(paths.moveAssets.src, {ignoreInitial: false}, _moveAssets);
watch(paths.html.src, {ignoreInitial: false}, _moveHTML);
watch(paths.scss.watch, {ignoreInitial: false}, _sassToCSS);
watch(paths.js.src, {ignoreInitial: false}, _concatJS);
};
const build = series(_moveTemplates, _moveAssets, _minifyHTML, _minifyCSS, _uglifyJS);
module.exports = {
dev,
build
};