-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
143 lines (130 loc) · 3.51 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
const gulp = require('gulp');
const concat = require('gulp-concat');
const header = require('gulp-header');
const rename = require("gulp-rename");
const sass = require('gulp-sass');
const htmlmin = require('gulp-html-minifier');
const imagemin = require('gulp-imagemin');
const uglify = require('gulp-uglify');
const replace = require('gulp-replace');
const browserSync = require('browser-sync').create();
const pkg = require('./package.json');
const paths = {
dev: {
styles: {
src: ['src/sass/style.scss'],
dist: 'src/styles'
}
},
prod: {
html: {
src: ['src/*.html'],
dist: 'dist/'
},
images: {
src: ['src/images/*', 'src/images/*/*'],
dist: 'dist/images'
},
fonts: {
src: ['src/fonts/*.*'],
dist: 'dist/fonts'
},
php: {
src: ['src/php/*.*'],
dist: 'dist/php'
},
styles: {
src: ['src/sass/style.scss'],
dist: 'dist/styles'
},
scripts: {
src: ['src/scripts/app.js'],
file: 'app.js',
dist: 'dist/scripts'
},
sync: {
baseDir: 'dist',
port: 4000
}
}
};
var banner = ['/*!\n',
' *<%= pkg.title %> v<%= pkg.version %>\n',
' * Copyright 2016-' + (new Date()).getFullYear(), ' <%= pkg.author %>\n',
' */\n',
''
].join('');
gulp.task('html', () => {
return gulp.src(paths.prod.html.src)
.pipe(replace('styles/style.css', 'styles/style.min.css'))
.pipe(replace('scripts/app.js', 'scripts/app.min.js'))
.pipe(htmlmin({
collapseWhitespace: true
}))
.pipe(gulp.dest(paths.prod.html.dist));
});
gulp.task('images', () => {
return gulp.src(paths.prod.images.src)
.pipe(imagemin())
.pipe(gulp.dest(paths.prod.images.dist));
});
gulp.task('fonts', () => {
return gulp.src(paths.prod.fonts.src)
.pipe(gulp.dest(paths.prod.fonts.dist));
});
gulp.task('php', () => {
return gulp.src(paths.prod.php.src)
.pipe(gulp.dest(paths.prod.php.dist));
});
gulp.task('sass-dev', () => {
return gulp.src(paths.dev.styles.src)
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest(paths.dev.styles.dist))
// .pipe(browserSync.reload({
// stream: true
// }))
// done();
});
gulp.task('sass', () => {
return gulp.src(paths.prod.styles.src)
.pipe(sass({
outputStyle: 'compressed'
}).on('error', sass.logError))
.pipe(header(banner, {
pkg: pkg
}))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(paths.prod.styles.dist))
.pipe(browserSync.reload({
stream: true
}))
});
gulp.task('js-minify', () => {
return gulp.src(paths.prod.scripts.src)
.pipe(concat(paths.prod.scripts.file))
.pipe(uglify())
.pipe(header(banner, {
pkg: pkg
}))
.pipe(rename({
suffix: '.min'
}))
.pipe(gulp.dest(paths.prod.scripts.dist))
.pipe(browserSync.reload({
stream: true
}))
});
gulp.task('browser-sync', () => {
browserSync.init({
server: {
baseDir: paths.sync.baseDir
},
port: paths.sync.port
})
});
// Dev
gulp.task('default', gulp.series('sass-dev'));
// Prod
gulp.task('build', gulp.series('html', 'fonts', 'php', 'sass', 'images', 'js-minify'));