brillout / goldpage

Page Builder.
Creative Commons Zero v1.0 Universal
57 stars 3 forks source link

Expose Node.js function for running dev build in watch mode #5

Closed chriscalo closed 5 years ago

chriscalo commented 5 years ago

Just an idea, feel free to discard if you disagree.

If goldpage exposed a Node.js function that ran the dev build in watch mode, it would mean users of the library wouldn't have to run goldpage dev on the command line. I prefer having control of starting the server myself instead of having goldpage start the server.

Here's what that could look like:

import { ssr, dev } from "goldpage";
import express from "express";

const app = express();
app.use(ssr.express);

// dev build with hot-reloading
if (process.env.NODE_ENV !== "production") {
  dev();
}

app.listen(3000);

Thoughts?

brillout commented 5 years ago

Would love this but it's problematic when you want to auto-restart your server. E.g. when doing nodemon ./path/to/server.js — whenever the server is auto-reloaded it will terminate require('goldpage').dev().

chriscalo commented 5 years ago

Would love this but it's problematic when you want to auto-restart your server. E.g. when doing nodemon ./path/to/server.js — whenever the server is auto-reloaded it will terminate require('goldpage').dev().

Now that I know that I can just run goldpage dev, I’ll probably create a separate npm script for the build and run it in parallel with my server. Thanks 👍