This repository has been archived on 2020-04-22. You can view files and clone it, but cannot push or open issues or pull requests.
victor-hugo/gulpfile.babel.js

66 lines
1.8 KiB
JavaScript
Raw Normal View History

import gulp from "gulp";
import { spawn } from "child_process";
import hugoBin from "hugo-bin"
import gutil from "gulp-util";
import postcss from "gulp-postcss";
import cssImport from "postcss-import";
import cssnext from "postcss-cssnext";
import BrowserSync from "browser-sync";
import webpack from "webpack";
import webpackConfig from "./webpack.conf";
const browserSync = BrowserSync.create();
const defaultArgs = ["-d", "../dist", "-s", "site", "-v"];
gulp.task("hugo", (cb) => buildSite(cb));
gulp.task("hugo-preview", (cb) => buildSite(cb, ["--buildDrafts", "--buildFuture"]));
2016-07-03 22:07:47 +00:00
gulp.task("build", ["css", "js", "hugo"]);
gulp.task("build-preview", ["css", "js", "hugo-preview"]);
2016-07-03 22:07:47 +00:00
gulp.task("css", () => (
gulp.src("./src/css/*.css")
.pipe(postcss([cssImport({from: "./src/css/main.css"}), cssnext()]))
.pipe(gulp.dest("./dist/css"))
.pipe(browserSync.stream())
));
2016-07-03 22:07:47 +00:00
gulp.task("js", (cb) => {
2016-07-03 22:07:47 +00:00
const myConfig = Object.assign({}, webpackConfig);
webpack(myConfig, (err, stats) => {
if (err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack]", stats.toString({
2016-07-03 22:07:47 +00:00
colors: true,
progress: true
}));
browserSync.reload();
2016-07-03 22:07:47 +00:00
cb();
});
});
gulp.task("server", ["hugo", "css", "js"], () => {
browserSync.init({
server: {
baseDir: "./dist"
}
});
gulp.watch("./src/js/**/*.js", ["js"]);
gulp.watch("./src/css/**/*.css", ["css"]);
gulp.watch("./site/**/*", ["hugo"]);
2016-07-03 22:07:47 +00:00
});
function buildSite(cb, options) {
const args = options ? defaultArgs.concat(options) : defaultArgs;
return spawn(hugoBin, args, {stdio: "inherit"}).on("close", (code) => {
if (code === 0) {
browserSync.reload();
cb();
} else {
browserSync.notify("Hugo build failed :(");
cb("Hugo build failed");
}
});
}