Giter Site home page Giter Site logo

Custom server support about preact-cli HOT 7 CLOSED

preactjs avatar preactjs commented on May 18, 2024
Custom server support

from preact-cli.

Comments (7)

robinvdvleuten avatar robinvdvleuten commented on May 18, 2024 2

@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?

from preact-cli.

robinvdvleuten avatar robinvdvleuten commented on May 18, 2024 2

@developit I've created a PR for exposing a compiler instance, let's continue the discussion there.

from preact-cli.

thangngoc89 avatar thangngoc89 commented on May 18, 2024

@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

from preact-cli.

robinvdvleuten avatar robinvdvleuten commented on May 18, 2024

@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 :)

from preact-cli.

thangngoc89 avatar thangngoc89 commented on May 18, 2024

@robinvdvleuten I think the prerendering is done in build step. Check out index.html, you'll see the rendered code of your index route. No need for a server here

from preact-cli.

developit avatar developit commented on May 18, 2024

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 preact-cli itself, but certainly I could see supporting something like this:

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 prerender({ url }).

from preact-cli.

developit avatar developit commented on May 18, 2024

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.

from preact-cli.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.