Commit 790d164f by Dan Allen

merge !36

resolves #43 switch from browser-sync to gulp-server-livereload
parents bc5cf0ae 7c115449
Pipeline #17501133 passed with stages
in 3 minutes 28 seconds
'use strict'
const connect = require('gulp-connect')
const path = require('path')
const gulp = require('gulp')
......@@ -28,11 +29,14 @@ gulp.task('format', () => format(jsFiles))
gulp.task('build', () => build(srcDir, destDir))
gulp.task('build:preview', ['build'], () => buildPreview(srcDir, destDir, previewSiteSrcDir, previewSiteDestDir))
gulp.task('build:preview', ['build'], () =>
buildPreview(srcDir, destDir, previewSiteSrcDir, previewSiteDestDir, connect.reload)
)
gulp.task('preview', ['build:preview'], () =>
preview(previewSiteDestDir, {
port: 5252,
livereload: process.env.LIVERELOAD === 'true',
watch: {
src: [srcDir, previewSiteSrcDir],
onChange: () => gulp.start('build:preview'),
......
......@@ -12,9 +12,8 @@
},
"devDependencies": {
"autoprefixer": "^7.1.6",
"browser-sync": "^2.18.13",
"browserify": "^14.5.0",
"chokidar": "^1.7.0",
"chokidar": "^2.0.1",
"cssnano": "^3.10.0",
"eslint": "^4.11.0",
"eslint-config-standard": "^10.2.1",
......@@ -24,6 +23,7 @@
"eslint-plugin-standard": "^3.0.1",
"gulp": "^3.9.1",
"gulp-concat": "^2.6.1",
"gulp-connect": "^5.2.0",
"gulp-eslint": "^4.0.0",
"gulp-imagemin": "^4.0.0",
"gulp-postcss": "^7.0.0",
......@@ -33,7 +33,6 @@
"handlebars": "^4.0.10",
"highlight.js": "^9.12.0",
"js-yaml": "^3.10.0",
"lodash.debounce": "^4.0.8",
"map-stream": "^0.0.7",
"merge-stream": "^1.0.1",
"postcss-calc": "^6.0.1",
......
......@@ -9,7 +9,7 @@ const requireFromString = require('require-from-string')
const vfs = require('vinyl-fs')
const yaml = require('js-yaml')
module.exports = async (src, dest, siteSrc, siteDest) => {
module.exports = async (src, dest, siteSrc, siteDest, sink) => {
const [uiModel, layouts] = await Promise.all([
loadSampleUiModel(siteSrc),
compileLayouts(src),
......@@ -17,7 +17,7 @@ module.exports = async (src, dest, siteSrc, siteDest) => {
registerHelpers(src),
])
vfs
const stream = vfs
.src('**/*.html', { base: siteSrc, cwd: siteSrc })
.pipe(
map((file, next) => {
......@@ -32,6 +32,9 @@ module.exports = async (src, dest, siteSrc, siteDest) => {
})
)
.pipe(vfs.dest(siteDest))
if (sink) stream.pipe(sink())
return stream
}
function loadSampleUiModel (siteSrc) {
......
'use strict'
const browserSync = require('browser-sync')
const debounce = require('lodash.debounce')
const connect = require('gulp-connect')
const chokidar = require('chokidar')
module.exports = (dest, opts) => {
opts = opts || {}
browserSync({
files: dest,
ghostMode: false,
notify: false,
open: false,
port: opts.port,
reloadDelay: 200,
reloadDebounce: 200,
ui: false,
server: {
baseDir: dest,
},
})
module.exports = (serveDir, opts) => {
let watch
if (opts) {
opts = Object.assign({}, opts)
watch = opts.watch
delete opts.watch
} else {
opts = {}
}
const watch = opts.watch
let onStart
if (watch && watch.src && watch.onChange) {
const onChangeThrottled = debounce(watch.onChange, 300)
const watcher = chokidar.watch(watch.src, { ignoreInitial: true })
watcher.on('all', () => onChangeThrottled())
onStart = () => {
chokidar
.watch(watch.src, { ignoreInitial: true })
.on('add', watch.onChange)
.on('change', watch.onChange)
.on('unlink', watch.onChange)
}
}
opts.root = serveDir
connect.server(opts, onStart)
}
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment