|
@ -7,6 +7,7 @@ const pug = require('gulp-pug'); |
|
|
const less = require('gulp-less'); |
|
|
const less = require('gulp-less'); |
|
|
const path = require('path'); |
|
|
const path = require('path'); |
|
|
const es = require('event-stream'); |
|
|
const es = require('event-stream'); |
|
|
|
|
|
const { getPages } = require('./util'); |
|
|
const browserSync = require('browser-sync').create(); |
|
|
const browserSync = require('browser-sync').create(); |
|
|
const reload = browserSync.reload; |
|
|
const reload = browserSync.reload; |
|
|
|
|
|
|
|
@ -16,7 +17,7 @@ let isProd = process.env.NODE_ENV === "production" |
|
|
|
|
|
|
|
|
let distPath = isProd?"dist":"node_modules/.gcache" |
|
|
let distPath = isProd?"dist":"node_modules/.gcache" |
|
|
|
|
|
|
|
|
let pageName = "index" |
|
|
let pageNames = getPages() |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 删除输出文件夹目录 |
|
|
* 删除输出文件夹目录 |
|
@ -70,14 +71,30 @@ function pageFn(name="index") { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function allTask(func = asset) { |
|
|
|
|
|
let tasks = pageNames.map(v=>{ |
|
|
|
|
|
return func(v) |
|
|
|
|
|
}) |
|
|
|
|
|
return parallel(...tasks) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 开发时监听 |
|
|
* 开发时监听 |
|
|
*/ |
|
|
*/ |
|
|
function watchTask() { |
|
|
function watchTask() { |
|
|
|
|
|
if(!pageNames.length) return |
|
|
|
|
|
const routes = {} |
|
|
|
|
|
pageNames.forEach(v=>{ |
|
|
|
|
|
routes['/'+v]= distPath+`/${v}.html` |
|
|
|
|
|
}) |
|
|
browserSync.init({ |
|
|
browserSync.init({ |
|
|
startPath: `/${pageName}.html`, |
|
|
startPath: ``, |
|
|
|
|
|
index: '/index.html', |
|
|
server: { |
|
|
server: { |
|
|
baseDir: `./${distPath}`, |
|
|
baseDir: `./${distPath}`, |
|
|
|
|
|
routes: { |
|
|
|
|
|
...routes |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
watch([`${srcPath}/public/**/*`], static) // series(removeStatic, static)
|
|
|
watch([`${srcPath}/public/**/*`], static) // series(removeStatic, static)
|
|
@ -88,18 +105,30 @@ function watchTask() { |
|
|
.on("add", reload) |
|
|
.on("add", reload) |
|
|
.on("change", reload) |
|
|
.on("change", reload) |
|
|
.on("unlink", reload) |
|
|
.on("unlink", reload) |
|
|
watch([`${srcPath}/css/**/*`,`${srcPath}/js/**/*`], asset(pageName)) |
|
|
pageNames.forEach(page=>{ |
|
|
|
|
|
watch([`${srcPath}/{css,js}/${page}/**`], asset(page)) |
|
|
.on("add", reload) |
|
|
.on("add", reload) |
|
|
.on("change", reload) |
|
|
.on("change", reload) |
|
|
.on("unlink", reload) |
|
|
.on("unlink", reload) |
|
|
watch([`${srcPath}/html/**/*`], pageFn(pageName)) |
|
|
}) |
|
|
|
|
|
// watch([`${srcPath}/css/**/*`,`${srcPath}/js/**/*`], allTask(asset))
|
|
|
|
|
|
// .on("add", reload)
|
|
|
|
|
|
// .on("change", reload)
|
|
|
|
|
|
// .on("unlink", reload)
|
|
|
|
|
|
pageNames.forEach(page=>{ |
|
|
|
|
|
watch([`${srcPath}/html/${page}.pug`], pageFn(page)) |
|
|
.on("add", reload) |
|
|
.on("add", reload) |
|
|
.on("change", reload) |
|
|
.on("change", reload) |
|
|
.on("unlink", reload) |
|
|
.on("unlink", reload) |
|
|
|
|
|
}) |
|
|
|
|
|
// watch([`${srcPath}/html/**/*`], allTask(pageFn))
|
|
|
|
|
|
// .on("add", reload)
|
|
|
|
|
|
// .on("change", reload)
|
|
|
|
|
|
// .on("unlink", reload)
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
exports.watch = series(remove,static, common,parallel(asset(pageName)),parallel(pageFn(pageName)),watchTask) |
|
|
exports.watch = series(remove,static, common, allTask(asset), allTask(pageFn), watchTask) |
|
|
exports.default = series(remove,static, common, parallel(asset("index"), asset("about")),parallel(pageFn("index"), pageFn("about"))) |
|
|
exports.default = series(remove,static, common, allTask(asset), allTask(pageFn)) |
|
|
|
|
|
|
|
|
exports.index = series(remove, static, common, asset("index"), pageFn("index")) |
|
|
exports.index = series(remove, static, common, asset("index"), pageFn("index")) |
|
|
exports.about = series(remove, static, common, asset("about"), pageFn("about")) |
|
|
exports.about = series(remove, static, common, asset("about"), pageFn("about")) |