-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
119 lines (106 loc) · 3.49 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
'use strict'
const gulp = require('gulp'),
watch = require('gulp-watch'),
//styles
sourcemaps = require('gulp-sourcemaps'),
prefixer = require('gulp-autoprefixer'),
// html
rigger = require('gulp-rigger'),
// clear
del = require('del'),
// loggers and notifiers
notify = require('gulp-notify'),
gulplog = require('gulplog'),
//accessory
combine = require('stream-combiner2').obj,
gulpIf = require('gulp-if'),
newer = require('gulp-newer');
const browserSync = require('browser-sync').create();
const config = {
html: {
src: "src/front/*.html",
dest: "views",
watch: "src/front/chunk/**/*.*",
},
styles: {
src: "src/front/css/*.css",
dest: "public/css/",
watch: "src/front/css/**/*.*",
},
scripts: {
src: "src/front/js/**/*.*",
dest: "public/js/",
watch: "src/front/js/**/*.*",
},
assets: {
src: "",
dest: "",
watch: "",
},
clean: ["public/css/*", "public/js/*", "views/*.html"],
server: {
src: ".",
watch: ["views/**/*.html", "public/css/**/*.*", "public/js/**/*.*"],
},
};
//for production use NODE_ENV=production gulp <task>
var isDev = !process.env.NODE_ENV || process.env.NODE_ENV == 'development';
/* clean dist folder */
gulp.task('clear', function(callback) {
return del(config.clean).then(paths => {
console.log('Deleted files and folders:\n', paths.join('\n'));
});;
});
/* compile html from partial */
gulp.task('html', function(callback) {
return combine( // make container
gulp.src(config.html.src), // find html
rigger(), // apply includes !!! add file before included !!!, it may crush task
gulp.dest(config.html.dest)) // put to build folder
.on('error', notify.onError(function(error) {
return {
title: 'HTML Error',
message: error.message
};
})); // show message if error
});
gulp.task('styles', function(callback) {
return combine(
gulp.src(config.styles.src),
gulpIf(isDev, sourcemaps.init()), // start sourcemap if development
rigger(), // or any CSS preprocessors
prefixer(), // add browser prefixes
gulpIf(isDev, sourcemaps.write()), // write sourcemap if development
gulp.dest(config.styles.dest))
.on('error', notify.onError(function(error) {
return {
title: 'Styles Error',
message: error.message
};
}));
});
gulp.task('scripts', function(callback) {
return gulp.src(config.scripts.src, {since: gulp.lastRun('assets')})
.pipe(gulp.dest(config.scripts.dest));
});
gulp.task('assets', function(callback) {
return gulp.src(config.assets.src, {since: gulp.lastRun('assets')})
.pipe(newer(config.asssets.dest))
.pipe(gulp.dest(config.assets.dest));
});
gulp.task('watch', function() {
gulp.watch(config.html.watch, gulp.series('html'));
gulp.watch(config.styles.watch, gulp.series('styles'));
gulp.watch(config.scripts.watch, gulp.series('scripts'));
// gulp.watch(config.assets.watch, gulp.series('assets'));
});
gulp.task('build', gulp.series('clear', gulp.parallel('html', 'styles', 'scripts')));
gulp.task('serve', function() {
browserSync.init({
server: config.server.src
});
browserSync.watch(config.server.watch).on('change', browserSync.reload);
});
gulp.task('dev',
gulp.series('build', gulp.parallel('watch')));
gulp.task('default', gulp.series('dev'));