Environment variables added for gulp tasks, renamed defaultArgs
This commit is contained in:
parent
8979bad9a0
commit
4f7c68fd3b
|
@ -10,13 +10,18 @@ import webpack from "webpack";
|
||||||
import webpackConfig from "./webpack.conf";
|
import webpackConfig from "./webpack.conf";
|
||||||
|
|
||||||
const browserSync = BrowserSync.create();
|
const browserSync = BrowserSync.create();
|
||||||
const defaultArgs = ["-d", "../dist", "-s", "site", "-v"];
|
|
||||||
|
|
||||||
|
// Hugo arguments
|
||||||
|
const hugoArgsDefault = ["-d", "../dist", "-s", "site", "-v"];
|
||||||
|
const hugoArgsPreview = ["--buildDrafts", "--buildFuture"];
|
||||||
|
|
||||||
|
// Development tasks
|
||||||
gulp.task("hugo", (cb) => buildSite(cb));
|
gulp.task("hugo", (cb) => buildSite(cb));
|
||||||
gulp.task("hugo-preview", (cb) => buildSite(cb, ["--buildDrafts", "--buildFuture"]));
|
gulp.task("hugo-preview", (cb) => buildSite(cb, hugoArgsPreview));
|
||||||
|
|
||||||
gulp.task("build", ["css", "js", "hugo"]);
|
// Build/production tasks
|
||||||
gulp.task("build-preview", ["css", "js", "hugo-preview"]);
|
gulp.task("build", ["css", "js"], (cb) => buildSite(cb, [], "production"));
|
||||||
|
gulp.task("build-preview", ["css", "js"], (cb) => buildSite(cb, hugoArgsPreview, "production"));
|
||||||
|
|
||||||
gulp.task("css", () => (
|
gulp.task("css", () => (
|
||||||
gulp.src("./src/css/*.css")
|
gulp.src("./src/css/*.css")
|
||||||
|
@ -50,8 +55,10 @@ gulp.task("server", ["hugo", "css", "js"], () => {
|
||||||
gulp.watch("./site/**/*", ["hugo"]);
|
gulp.watch("./site/**/*", ["hugo"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
function buildSite(cb, options) {
|
function buildSite(cb, options, environment = "development") {
|
||||||
const args = options ? defaultArgs.concat(options) : defaultArgs;
|
const args = options ? hugoArgsDefault.concat(options) : hugoArgsDefault;
|
||||||
|
|
||||||
|
process.env.NODE_ENV = environment;
|
||||||
|
|
||||||
return spawn(hugoBin, args, {stdio: "inherit"}).on("close", (code) => {
|
return spawn(hugoBin, args, {stdio: "inherit"}).on("close", (code) => {
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
|
|
Reference in New Issue