-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.babel.js
168 lines (142 loc) · 3.62 KB
/
gulpfile.babel.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
'use strict';
import gulp from "gulp";
var watch = require('gulp-watch'),
prefixer = require('gulp-autoprefixer'),
uglify = require('gulp-uglify'),
sass = require('gulp-sass'),
cssmin = require('gulp-minify-css'),
browserSync = require("browser-sync"),
reload = browserSync.reload,
babel = require("gulp-babel"),
plumber = require('gulp-plumber'),
sourcemaps = require('gulp-sourcemaps'),
terser = require('gulp-terser');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const webpackConfig = require('./webpack.config.js');
var path = {
build: {
html: 'build/',
js: 'build/js/',
css: 'build/css/',
img: 'build/img/',
fonts: 'build/fonts/',
},
src: {
html: 'src/*.html',
js: 'src/js/*.js',
scss: 'src/scss/*.scss',
img: 'src/img/**/*.*',
fonts: 'src/fonts/**/*.*',
},
watch: {
html: 'src/**/*.html',
js: ['src/js/**/*.js', 'src/js/**/*.vue', '*.json'],
scss: 'src/scss/**/*.scss',
img: 'src/img/**/*.*',
fonts: 'src/fonts/**/*.*',
}
};
const config = {
server: {
baseDir: "./build"
},
tunnel: false,
host: 'localhost',
port: 9000,
logPrefix: "Frontend_Devil",
open: false
};
/**
* Compilers for HTML & assets
*/
// Compile HTML
const compileHtml = () => {
return gulp.src([path.src.html])
.pipe(plumber())
.pipe(gulp.dest(path.build.html))
.pipe(reload({
stream: true
}));
};
// Compile Styles
const compileStyles = () => {
return gulp.src(path.src.scss)
// .pipe(sourcemaps.init())
.pipe(sass({
includePaths: ['node_modules']
}).on('error', sass.logError))
.pipe(prefixer())
.pipe(cssmin())
// .pipe(sourcemaps.write('.', { sourceRoot: 'css-source' }))
.pipe(gulp.dest(path.build.css))
.pipe(reload({
stream: true
}));
};
// Compile JS
const compileJS = () => {
return gulp.src(path.src.js)
.pipe(webpackStream(webpackConfig), webpack)
.pipe(terser())
.pipe(gulp.dest(path.build.js))
.pipe(reload({
stream: true
}));
};
// Compile Images
const compileImages = () => {
return gulp.src(path.src.img)
.pipe(gulp.dest(path.build.img))
.pipe(reload({
stream: true
}));
};
// Compile Fonts
const compileFonts = () => {
return gulp.src(path.src.fonts)
.pipe(gulp.dest(path.build.fonts))
.pipe(reload({
stream: true
}));
};
// Compile everything together
const compile = gulp.parallel(compileHtml, compileStyles, compileJS, compileImages, compileFonts);
compile.description = 'compile all sources'
/**
* Watchers for html & assets
*/
const watchHtml = () => {
return gulp.watch(path.watch.html, compileHtml);
};
const watchStyles = () => {
return gulp.watch(path.watch.scss, compileStyles);
};
const watchJS = () => {
return gulp.watch(path.watch.js, compileJS);
};
const watchImages = () => {
return gulp.watch(path.watch.img, compileImages);
};
const watchAll = gulp.parallel(watchHtml, watchStyles, watchJS, watchImages);
const webserver = () => {
return browserSync(config);
};
const serve = gulp.series(compile, webserver);
// Default Gulp Task
const defaultTasks = gulp.parallel(serve, watchAll);
export {
compileHtml,
compileStyles,
compileJS,
compileImages,
compileFonts,
watchHtml,
watchImages,
watchJS,
watchStyles,
watchAll,
compile,
serve
}
export default defaultTasks