Giter VIP home page Giter VIP logo

react-ssr-template's Introduction

React application with Streaming Server Side Rendering

A simple template for a website with SSR (with streams) and React 18 with a brand new API โ€” https://github.com/reactwg/react-18/discussions ๐Ÿ”ฅ๐Ÿ”ฅ๐Ÿ”ฅ

๐Ÿš€ Just start with

npm i && make dev

If you want to see this project in action: http://174.138.13.187:5000/

๐Ÿšง ๐Ÿ› ๏ธ Work In Progress ๐Ÿ› ๏ธ ๐Ÿšง

Base commands

First off, I'm using make) It's not necessary, but as I think it is much powerful than npm from the box.

So, let's talk about base commands.

  • make dev โ€” starts a dev-server with a file-watcher + tsc in a watch mode.
  • make prod โ€” builds a production version of your application.
  • make start-prod โ€” starts built application. Quite useful after make prod.
  • make test โ€” starts eslint, prettier, tsc and unit-tests

Technologies

  • typescript as the main language.
  • Express.js as a server. I think about fastify as a replacement for Express.js.
  • React as a view layer. Render to a stream is used for SSR.
  • React-query as a layer for working with an external data.
  • Own version of CSS-in-JS. Inspired by aphrodite. You can find an implementation here. I need my own implementation, cause there is no any other ready solutions in CSS-in-JS, which will work with new React SSR API.
  • My own router, which was created to work with redux. Find more info here. Checkout tests, you will find all cases there. Redux is used under the hood. If you'd like to use redux for your own state โ€” you can wrap your application with a Provider. Redux in the router uses its own context.
  • webpack + esbuild to build the project.
  • pino as fast and light logger.
  • mocha + chai + sinon + React testing library to work with tests.
  • eslint to find mistakes in the code.
  • prettier to forget about code style.

I've tried to add as many comments in the source code as I could. So, all interesting places have dozens of comments to describe, what's happening there. I do apologize for my english)

As you can see, there is no any state manager for your own data. Redux is used in the router only, react-query is used for any data-fetching. So, you can use anything for any additional data-managment.

If you want to figure out, how it works, just start from:

But I recommend you to start from https://github.com/reactwg/react-18/discussions cause, there a lot of useful information, which can help you to work with current repo.

Fell free to ask me anything in the issues.

react-ssr-template's People

Contributors

artem-malko avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-ssr-template's Issues

QUESTION: route based package chunking

hi,

The project is great, and I want to thank you first.

I'm working on a performance-focused project, and I want to chunk and separate route-based packages.

vendor: {
          test: /[\\/]node_modules[\\/]/,
          enforce: true,
          chunks: 'all',
          name(module: any) {
            const packageName = module.context.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1];

            switch (packageName) {
              case 'react':
              case 'react-dom':
              case 'scheduler':
              case 'object-assign':
                return 'react';
              case 'path-to-regexp':
              case 'uuid':
                return 'rarely';
              default:
                return 'vendor';
            }
          },
        },

I want to separate them like the structure here, such as homeVendor, usersVendor, etc., and load only that vendor on the relevant page. Separating them is not a problem, but how can I decide which vendor to load on which route? Is it possible to do something like this?

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.