-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
96 lines (85 loc) · 3.03 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
"use strict";
const gulp = require("gulp");
const webpack = require("webpack-stream");
const browsersync = require("browser-sync");
const dist = "./dist/";
gulp.task("copy-html", () => {
return gulp.src("./src/index.html")
.pipe(gulp.dest(dist))
.pipe(browsersync.stream());
});
gulp.task("build-js", () => {
return gulp.src("./src/js/main.js")
.pipe(webpack({
mode: 'development',
output: {
filename: 'script.js'
},
watch: false,
devtool: "source-map",
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', {
debug: true,
corejs: 3,
useBuiltIns: "usage"
}]]
}
}
}
]
}
}))
.pipe(gulp.dest(dist))
.on("end", browsersync.reload);
});
gulp.task("copy-assets", () => {
return gulp.src("./src/assets/**/*.*")
.pipe(gulp.dest(dist + "/assets"))
.on("end", browsersync.reload);
});
gulp.task("watch", () => {
browsersync.init({
server: "./dist/",
port: 4000,
notify: true
});
gulp.watch("./src/index.html", gulp.parallel("copy-html"));
gulp.watch("./src/assets/**/*.*", gulp.parallel("copy-assets"));
gulp.watch("./src/js/**/*.js", gulp.parallel("build-js"));
});
gulp.task("build", gulp.parallel("copy-html", "copy-assets", "build-js"));
gulp.task("build-prod-js", () => {
return gulp.src("./src/js/main.js")
.pipe(webpack({
mode: 'production',
output: {
filename: 'script.js'
},
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', {
corejs: 3,
useBuiltIns: "usage"
}]]
}
}
}
]
}
}))
.pipe(gulp.dest(dist));
});
gulp.task("default", gulp.parallel("watch", "build"));