-
-
Notifications
You must be signed in to change notification settings - Fork 376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom server support #70
Comments
@robinvdvleuten I think preact-cli and next.js are 2 different beasts. You can serve the static build with any server. So no need for support from preact-cli. Just build your own :D |
@thangngoc89 I am aware of that, but the preact-cli also has supports for prerendering. It would be nice if there is some sort of exposed API for this so that you still can rely on the webpack / babel configuration of this project :) |
@robinvdvleuten I think the prerendering is done in build step. Check out |
If we end up with a UMD or CommonJS bundle output from something like #71, you could use preact-cli as an opaque compiler within a Node server. I'm not sure it'd fit perfectly into import { h } from 'preact';
import express from 'express';
import { build } from 'preact-cli';
import renderToString from 'preact-render-to-string';
const app = build('./client', { format: 'umd' }).then( output => require(output.main) );
const app = express();
app.get( (req, res) => {
app.then( App => {
let body = renderToString(<App url={req.path} />);
res.send(`<!doctype html><html lang="en">${body}`);
});
});
app.listen(process.env.PORT); Or, maybe we expose an full API where you could trigger and handle a client build, or invoke a high level API for SSR like |
@developit that's exactly the kind of interface I meant! I do not expect that preact-cli becomes some kind of prext.js, but it would be great if it provides some kind of interface / functionality to build this kind of tooling upon. The only thing the preact-cli should do extra I guess is to expose the build process. Is there any way I can help with this? |
Any experimentation you have time to do would be appreciated. The API we can solidify later, but I'd love to get some experiments done around returning a reusable "preact compiler" instance. |
@developit I've created a PR for exposing a compiler instance, let's continue the discussion there. |
Instead of having a static production-like server when building for production. It would definitely be awesome to have some kind of "custom server" type of output like next.js has.
The text was updated successfully, but these errors were encountered: