Code Monkey home page Code Monkey logo

Comments (15)

lukeed avatar lukeed commented on May 18, 2024 5

Yo~! serve is actually being removed going forward since it's the largest dependency, least-commonly used, and is really only used for test service workers in a production setting.

We'll include good/better documentation as to how achieve the same actions going forward πŸ‘

from preact-cli.

oren avatar oren commented on May 18, 2024 4

Here is my understanding:

  1. npm start (or preact watch or npm run dev) - run it during development. Supports hot-reloading, and a few other goodies. Basically, whenever you change a code, the browser immediately displays the new changes without having to manually reload the browser.
  2. npm run build (or preact build) - create production ready code inside the build folder
  3. npm run serve (or preact build + preact serve) - build and run production-like server
  4. preact serve - run production-like server (without build)

from preact-cli.

Download avatar Download commented on May 18, 2024 1

Sorry to revive this old issue. I am studying up on Preact CLI but there is this one aspect I cannot yet wrap my head around and this issue most closely describes it.

If preact serve is used to test the build, but not really intended for production, then how do we deploy it to production? Because I cannot really find the code in the default project that starts the server. Are we supposed to say, add Express and create a server.js file that then uses the App component? This part is not clear to me yet and I cannot find any docs on it.

from preact-cli.

Sigmus avatar Sigmus commented on May 18, 2024 1

After you build you are responsible for deploying and serving the generated build folder (which is a static webapp).

from preact-cli.

thangngoc89 avatar thangngoc89 commented on May 18, 2024

@oren You can use it after run preact build to see the production version of your site before deploying. Many thing is only enable on production (for now) like Service worker, HTTP2 server push, ...

from preact-cli.

marvinhagemeister avatar marvinhagemeister commented on May 18, 2024

The command preact serve is the one you would want to use during development. It supports hot-reloading, and a few other goodies. Basically, whenever you change a code, the browser immediately displays the new changes without having to manually reload the browser.

from preact-cli.

lukeed avatar lukeed commented on May 18, 2024

@marvinhagemeister Actually serve is the production-like server. What you described is preact watch (which is npm run dev by default). πŸ˜… I've made that mistake too.

from preact-cli.

marvinhagemeister avatar marvinhagemeister commented on May 18, 2024

@lukeed oh shoot! That is embarrassing πŸ˜…

from preact-cli.

lukeed avatar lukeed commented on May 18, 2024

@oren that is 100% correct

@marvinhagemeisterΒ No it's not -- don't worry about it! πŸ˜„

from preact-cli.

developit avatar developit commented on May 18, 2024

One addendum: currently, npm start will actually check the NODE_ENV environment variable. If it is set to "production", it will run npm run serve. If it's any other value, it will run npm run dev (the development server).

There was some question around this, and I think that's warranted - it's probably worth making sure we're doing the best possible thing here. For my own purposes, I know a lot of hosts assume npm i && npm start will produce a running production server, so I wanted to have that work out-of-the-box for things like now.sh.

from preact-cli.

kuldeepkeshwar avatar kuldeepkeshwar commented on May 18, 2024

@developit what is the preferred way of hosting preact app in production? npm run serve uses simplehttp2server
but simplehttp2server itself says This server is for development purposes only..
How to take advantage of http2 push when preact app is hosted behind a proxy like Nginx

from preact-cli.

thangngoc89 avatar thangngoc89 commented on May 18, 2024

@kuldeepkeshwar nginx itself doesn't support http2 push so you can't do anything about it.
There are many option to host a static sites with h2 push support.

  • use cdns, like cloudflare, they support h2 push by sending the right header
  • static hosting service like netlify, firebase hosting, ...

from preact-cli.

oren avatar oren commented on May 18, 2024

from preact-cli.

reznord avatar reznord commented on May 18, 2024

preact serve is used for testing the production build locally where you can test the lighthouse scores, check if there are any performance related issue or not.

from preact-cli.

Download avatar Download commented on May 18, 2024

My confusion is that I did not realize the default template gives a client-side only app. Now it makes sense. Thanks!

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.