forked from agenciam3/Desenvolvedor-M3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
108 lines (95 loc) · 2.26 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
const path = require("path");
const { series, src, dest, parallel, watch } = require("gulp");
const webpack = require("webpack");
const del = require("del");
const autoprefixer = require("gulp-autoprefixer");
const sass = require("gulp-sass")(require("sass"));
const sourcemaps = require("gulp-sourcemaps");
const browserSync = require("browser-sync").create();
const webpackConfig = require("./webpack.config.js");
const paths = {
scripts: {
src: "src/ts/index.ts",
watch: "src/ts/**/*.ts",
},
styles: {
src: "src/scss/main.scss",
},
img: {
src: "src/img/**/*",
},
html: {
src: "src/index.html",
},
dest: "dist",
temp: ".tmp",
};
function clean() {
return del([paths.dest, paths.temp]);
}
function server() {
browserSync.init({
server: {
baseDir: "./dist",
},
});
}
function styles() {
return src(paths.styles.src)
.pipe(sourcemaps.init())
.pipe(sass())
.pipe(
autoprefixer({
cascade: false,
})
)
.pipe(sourcemaps.write())
.pipe(dest(paths.dest))
.pipe(browserSync.stream());
}
function scripts() {
return new Promise((resolve) =>
webpack(webpackConfig(paths), (err, stats) => {
if (err) console.log("Webpack", err);
console.log(
stats.toString({
all: false,
modules: true,
maxModules: 0,
errors: true,
warnings: true,
moduleTrace: true,
errorDetails: true,
colors: true,
chunks: true,
})
);
resolve();
})
);
}
function html() {
return src(paths.html.src).pipe(browserSync.stream()).pipe(dest(paths.dest));
}
function img() {
return src(paths.img.src).pipe(dest(paths.dest + "/img"));
}
const build = series(clean, parallel(styles, scripts, html, img));
const dev = () => {
watch(paths.scripts.watch, { ignoreInitial: false }, scripts).on(
"change",
browserSync.reload
);
watch(paths.styles.src, { ignoreInitial: false }, styles);
watch(paths.img.src, { ignoreInitial: false }, img);
watch(paths.html.src, { ignoreInitial: false }, html).on(
"change",
browserSync.reload
);
server();
};
exports.build = build;
exports.server = server;
exports.styles = styles;
exports.scripts = scripts;
exports.default = dev;