Browse Source

Switch to build-thing + budo-express

feature/node-rewrite
Sven Slootweg 1 year ago
parent
commit
f40ce08148
3 changed files with 86 additions and 132 deletions
  1. +73
    -0
      bin/server.js
  2. +13
    -0
      build.js
  3. +0
    -132
      gulpfile.js

+ 73
- 0
bin/server.js View File

@@ -0,0 +1,73 @@
"use strict";

const budoExpress = require("budo-express");
const path = require("path");

budoExpress({
port: 8000,
debug: true,
expressApp: require("../src/app")(),
basePath: path.resolve(__dirname, ".."),
entryPath: "src/client/index.jsx",
publicPath: "public",
bundlePath: "js/bundle.js",
livereload: "**/*.{css,html}",
browserify: {
extensions: [".jsx"],
plugin: [
"browserify-hmr"
],
transform: [
["babelify", {
presets: ["@babel/preset-env", "@babel/preset-react"],
// plugins: ["react-hot-loader/babel"]
}]
]
},
});


// const app = require("../src/app.js")();

// if (process.env.NODE_ENV === "development") {
// const budo = require("budo");

// function projectPath(targetPath) {
// return path.resolve(__dirname, "..", targetPath);
// }

// budo(projectPath("src/client/index.jsx"), {
// watchGlob: projectPath("public/css/*.css"),
// live: "**/*.css",
// stream: process.stdout,
// port: 8000,
// dir: projectPath("public"),
// serve: "js/bundle.js",
// debug: true,
// browserify: {
// extensions: [".jsx"],
// plugin: [
// "browserify-hmr"
// ],
// transform: [
// ["babelify", {
// presets: ["@babel/preset-env", "@babel/preset-react"],
// plugins: ["react-hot-loader/babel"]
// }]
// ]
// },
// middleware: function (req, res, next) {
// app.handle(req, res, (err) => {
// if (err != null && err instanceof Error) {
// res.send("<pre>" + err.stack + "</pre>");
// } else {
// next(err);
// }
// });
// }
// });
// } else {
// app.listen(3000).on("listening", () => {
// console.log("Listening...");
// });
// }

+ 13
- 0
build.js View File

@@ -0,0 +1,13 @@
"use strict";

const buildThing = require("build-thing");

let scssTask = buildThing.core.defineTask(() => {
return buildThing.core.pipeline([
buildThing.core.watch("src/scss/**/*.scss"),
buildThing.scssTransform(),
buildThing.core.saveToDirectory("public/css")
]);
});

buildThing.runner(scssTask);

+ 0
- 132
gulpfile.js View File

@@ -1,132 +0,0 @@
'use strict';

const Promise = require("bluebird");
const path = require("path");
const gulp = require("gulp");
const webpackStream = require("webpack-stream");
const webpack = require("webpack");
const gulpCached = require("gulp-cached");
const gulpRename = require("gulp-rename");
const gulpNodemon = require("gulp-nodemon");
const gulpLivereload = require("gulp-livereload");
const gulpNamedLog = require("gulp-named-log");

const presetSCSS = require("@joepie91/gulp-preset-scss");
const partialPatchLivereload = require("@joepie91/gulp-partial-patch-livereload-logger");

const serverWaiter = require("./lib/build/wait-for-server")(3000);

const nodemonLogger = gulpNamedLog("nodemon");
const livereloadLogger = gulpNamedLog("livereload");

partialPatchLivereload(gulpLivereload);

let nodemon;

let sources = {
scss: ["./scss/**/*.scss"]
}

/* The following resolves JacksonGariety/gulp-nodemon#33 */
process.once("SIGINT", function() {
process.exit(0);
});

function tryReload(target) {
if (!serverWaiter.isWaiting()) {
if (typeof target === "string") {
gulpLivereload.changed(target);
} else if (target.path != null) {
if (Array.isArray(target.path)) {
gulpLivereload.changed(target.path[0]);
} else {
gulpLivereload.changed(target.path);
}
}
}
}

function queueFullReload() {
return Promise.try(() => {
nodemonLogger.log("Waiting for server to start listening...")
return serverWaiter.wait();
}).then(() => {
nodemonLogger.log("Server started!")
tryReload("*");
});
}

gulp.task("scss", () => {
return gulp.src(sources.scss)
.pipe(presetSCSS({
basePath: __dirname
}))
.pipe(gulp.dest("./public/css"));
});

gulp.task("webpack", () => {
return gulp.src("./frontend/index.js")
.pipe(webpackStream({
watch: true,
module: {
preLoaders: [{
test: /\.tag$/,
loader: "riotjs-loader",
exclude: /node_modules/,
query: {
type: "babel",
template: "pug",
parserOptions: {
js: {
presets: ["es2015-riot"]
}
}
}
}],
loaders: [
{ test: /\.js$/, loader: "babel-loader" },
{ test: /\.json$/, loader: "json-loader" }
]
},
plugins: [ new webpack.ProvidePlugin({riot: "riot"}) ],
resolveLoader: { root: path.join(__dirname, "node_modules") },
resolve: {
extensions: [
"",
".tag",
".web.js", ".js",
".web.json", ".json"
]
},
debug: false
}))
.pipe(gulpRename("bundle.js"))
.pipe(gulp.dest("./public"));
});

gulp.task("nodemon", ["scss"], () => {
nodemon = gulpNodemon({
script: "./app.js",
delay: 500,
ignore: ["node_modules", "public", "gulpfile.js"],
quiet: true
}).on("restart", (cause) => {
nodemonLogger.log("Restarting... caused by:", cause.join(" / "));
serverWaiter.reportRestart();
}).on("start", () => {
return queueFullReload()
});
});

gulp.task("watch-server", ["nodemon"], () => {
gulpLivereload.listen({
quiet: true
});

gulp.watch(sources.scss, ["scss"]);

gulp.watch("./public/**/*", tryReload);
});

gulp.task("watch", ["watch-server", "webpack"]);
gulp.task("default", ["watch"]);

Loading…
Cancel
Save