From e798df62002ca254b242f6e5d86bb3bde5837eeb Mon Sep 17 00:00:00 2001 From: Marek Lichtner Date: Mon, 14 May 2018 16:16:17 +0200 Subject: [PATCH] Added start-preview script and server-preview task (#90) --- README.md | 12 ++++++++++++ gulpfile.babel.js | 8 ++++++-- package.json | 1 + 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2f0eb0a..958403d 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,18 @@ or gulp server ``` +or for developing your website with `hugo server --buildDrafts --buildFuture`, use: + +```bash +npm run start-preview +``` + +or + +```bash +gulp server-preview +``` + Then visit http://localhost:3000/ *- or a new browser windows popped-up already -* to preview your new website. BrowserSync will automatically reload the CSS or refresh the whole page, when stylesheets or content changes. ### Static build diff --git a/gulpfile.babel.js b/gulpfile.babel.js index 1b44c11..8dca99a 100644 --- a/gulpfile.babel.js +++ b/gulpfile.babel.js @@ -20,6 +20,10 @@ const hugoArgsPreview = ["--buildDrafts", "--buildFuture"]; gulp.task("hugo", (cb) => buildSite(cb)); gulp.task("hugo-preview", (cb) => buildSite(cb, hugoArgsPreview)); +// Run server tasks +gulp.task("server", ["hugo", "css", "js", "fonts"], (cb) => runServer(cb)); +gulp.task("server-preview", ["hugo-preview", "css", "js", "fonts"], (cb) => runServer(cb)); + // Build/production tasks gulp.task("build", ["css", "js", "fonts"], (cb) => buildSite(cb, [], "production")); gulp.task("build-preview", ["css", "js", "fonts"], (cb) => buildSite(cb, hugoArgsPreview, "production")); @@ -56,7 +60,7 @@ gulp.task('fonts', () => ( )); // Development server with browsersync -gulp.task("server", ["hugo", "css", "js", "fonts"], () => { +function runServer() { browserSync.init({ server: { baseDir: "./dist" @@ -66,7 +70,7 @@ gulp.task("server", ["hugo", "css", "js", "fonts"], () => { gulp.watch("./src/css/**/*.css", ["css"]); gulp.watch("./src/fonts/**/*", ["fonts"]); gulp.watch("./site/**/*", ["hugo"]); -}); +}; /** * Run hugo and build the site diff --git a/package.json b/package.json index 59130ad..b964a54 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "build": "gulp build", "build-preview": "gulp build-preview", "start": "gulp server", + "start-preview": "gulp server-preview", "lint": "eslint src" }, "author": "",