-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
60 lines (51 loc) · 1.67 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
const sass = require("gulp-sass");
const { src,dest, watch } = require("gulp");
const sync = require("browser-sync").create();
const uglify = require("gulp-uglify");
const config = {
buildDir : "./build/**/*",
jsSource : "./src/js/**/*.js",
sassSource : "./src/scss/**/*.scss",
cssOutput : "./build",
jsOutput : "./build/js",
serverDir : "./build",
htmlSource: "./src/*.html",
htmlOutput: "./build",
assetsSource : "./assets/**/*",
assetsOutput : "./build/assets"
}
const copyJS = () => src(config.jsSource).pipe(dest(config.jsOutput))
const copytHTML = () => src(config.htmlSource).pipe(dest(config.htmlOutput))
const copyAssets = () => src(config.assetsSource).pipe(dest(config.assetsOutput))
const uglifyJS = () => src(config.jsSource).pipe(uglify()).pipe(dest(config.jsOutput))
const transpileSass = () => src(config.sassSource).pipe(sass().on('error',sass.logError)).pipe(dest(config.cssOutput))
const watchJS =() => watch(config.jsSource).on("change",copyJS)
const watchSass = () => watch(config.sassSource).on("change",transpileSass)
const watchHTML = () => watch(config.htmlSource).on("change",copytHTML)
const watchAssets = () => watch(config.assetsSource).on("change",copyAssets)
const watchBuild =() => watch(config.buildDir).on("all", sync.reload)
const buildDev = () => {
copyJS()
copytHTML()
copyAssets()
transpileSass()
}
function run(){
buildDev()
serve()
watchSass()
watchJS()
watchHTML()
watchAssets()
watchBuild()
}
function serve(){
sync.init({
server:{
baseDir: config.serverDir
}
})
}
exports.uglify = uglifyJS
exports.run = run
exports.sass = transpileSass