From f40ce08148ab61306afbb5d5357e1460d055512e Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Sat, 20 Apr 2019 21:43:00 +0200 Subject: [PATCH] Switch to build-thing + budo-express --- bin/server.js | 73 ++++++++++++++++++++++++++++ build.js | 13 +++++ gulpfile.js | 132 -------------------------------------------------- 3 files changed, 86 insertions(+), 132 deletions(-) create mode 100644 bin/server.js create mode 100644 build.js delete mode 100644 gulpfile.js diff --git a/bin/server.js b/bin/server.js new file mode 100644 index 0000000..e4c3424 --- /dev/null +++ b/bin/server.js @@ -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("
" + err.stack + "
"); +// } else { +// next(err); +// } +// }); +// } +// }); +// } else { +// app.listen(3000).on("listening", () => { +// console.log("Listening..."); +// }); +// } diff --git a/build.js b/build.js new file mode 100644 index 0000000..a191513 --- /dev/null +++ b/build.js @@ -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); diff --git a/gulpfile.js b/gulpfile.js deleted file mode 100644 index 58d78bc..0000000 --- a/gulpfile.js +++ /dev/null @@ -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"]);