-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add global styles and react app entry point; update README
- Loading branch information
Showing
20 changed files
with
162 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,56 @@ | ||
# template-for-react-ts-ssr-hmr | ||
|
||
Template for a project with React, TypeScript, SSR, HMR. Template imply using CSS Modules and Stylus. But it can be easily changed. | ||
Template for a project with React, TypeScript, SSR, and HMR. The template implies the use of CSS Modules and Stylus. | ||
|
||
## Quick start: | ||
## Quick start: | ||
|
||
To copy the template in an empty local folder without creating of a repo or in an existing repo use the following: | ||
|
||
```shell | ||
npx degit Kallenju/template-for-react-ts-ssr-hmr | ||
``` | ||
|
||
Install packages and run development servers: | ||
Install packages and run development servers: | ||
|
||
```shell | ||
npm install | ||
|
||
npm run dev | ||
``` | ||
|
||
## Structure of the template | ||
|
||
### Structure of the source folder (`./src`) | ||
|
||
- **assets** | ||
- **styles** | ||
- **body** | ||
- **html** | ||
- **root** | ||
- **client** | ||
- **server** | ||
- **shared** | ||
- **Header** | ||
- **Layout** | ||
- **types** | ||
|
||
## How it works | ||
|
||
`./src` contains `App.tsx`, which is the entry point of the React app. It imports components from `./src/shared` and global styles from `./assets/styles/`. `App.tsx` is in turn imported be server and client files in `./src/server/` and `./src/client/`, respectively. | ||
|
||
The `app.get()` method specifies a callback function that will render to string React component from `App.tsx` and past it in a HTML template, whenever there is an HTTP GET request with a path ('/') relative to the site root. HTML template are in `./src/server`. | ||
|
||
After the `load` event is fired, the client code `hydrate` obtained React component. | ||
|
||
## What is used in the template? | ||
|
||
### Hot module replacement | ||
### Hot Module Replacement | ||
|
||
- express server | ||
- react-refresh-webpack-plugin | ||
- React Fast Refresh | ||
- Webpack modules and plugins (webpack-dev-middleware, webpack-hot-middleware, webpack.HotModuleReplacementPlugin) | ||
|
||
### Server-Side Rendering | ||
|
||
- express server |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import React from 'react'; | ||
import { Layout } from './shared/Layout'; | ||
import { Header } from './shared/Header'; | ||
import './assets/styles/main.global.styl'; | ||
|
||
export default function App(): React.ReactElement { | ||
return ( | ||
<Layout> | ||
<Header /> | ||
</Layout> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
body | ||
margin 0 | ||
min-width 320px | ||
font-family --font-family-primary, sans-serif | ||
font-size --font-size_sm | ||
font-weight --font-weight_xs | ||
line-height --line-height_xs | ||
background-color --color-white |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import 'body' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
html | ||
box-sizing border-box | ||
font-size 0.625em | ||
|
||
* | ||
box-sizing inherit | ||
|
||
&::before | ||
box-sizing inherit | ||
|
||
&::after | ||
box-sizing inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import 'html' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@import './root' | ||
@import './html' | ||
@import './body' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@import 'root'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
--container-width = 1400px | ||
--container-margins = 55px | ||
--container-margins_md = 31px | ||
--container-margins_sm = 27px | ||
--container-margins_xs = 21px | ||
--font-family-primary = 'Roboto' | ||
--font-family-secondary = 'ttfirsneue' | ||
--font-size_xxs = 1.20rem | ||
--font-size_xs = 1.40rem | ||
--font-size_sm = 1.60rem | ||
--font-size_md = 1.80rem | ||
--font-size_lg = 2.00rem | ||
--font-size_xl = 2.40rem | ||
--font-size_xxl = 3.40rem | ||
--line-height_xs = 1.04 | ||
--line-height_sm = 1.17 | ||
--line-height_md = 1.29 | ||
--line-height_lg = 1.38 | ||
--line-height_xl = 1.75 | ||
--font-weight_xs = 400 | ||
--font-weight_sm = 500 | ||
--font-weight_md = 600 | ||
--font-weight_lg = 700 | ||
--font-weight_xl = 800 | ||
--warning-color-primary = #ff3030 | ||
--success-color-primary = #7cbc4a | ||
--brend-color = #ff6e30 | ||
--background-color-primary = #ff5c00 | ||
--background-color-secondary = #202020 | ||
--color-focus-primary = #ff6e30 | ||
--color-hover-primary = #bc572b | ||
--color-active-primary = #ce4307 | ||
--border-color-primary = #ff6e30 | ||
--border-color-secondary = #ce4307 | ||
--text-color-primary = #fff | ||
--text-color-secondary = #202020 | ||
--form-text-color-primary = #202020 | ||
--color-dark-grey = #202020 | ||
--color-middle-grey = #999 | ||
--color-light-grey = #e9e9e9 | ||
--color-white = #fff | ||
--color-black = #000 | ||
--transition-time_slow = 0.210s | ||
--transition-time_fast = 0.100s | ||
|
||
--breakpoint_xs = 40em | ||
--breakpoint_sm = 56em | ||
--breakpoint_md = 66em | ||
--breakpoint_lg = 82em | ||
--grid-columns = 12 | ||
--grid-gap = 3.00rem | ||
--link_css-effects = 'plain' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
import React from 'react'; | ||
import ReactDom from 'react-dom/client'; | ||
import Header from '../shared/Header'; | ||
import App from '../App'; | ||
|
||
window.addEventListener('load', () => { | ||
const container: Element | null = document.querySelector('#react_root'); | ||
|
||
if (container) { | ||
ReactDom.hydrateRoot(container, <Header />); | ||
ReactDom.hydrateRoot(container, <App />); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import express from 'express'; | ||
import React from 'react'; | ||
import ReactDOMServer from 'react-dom/server'; | ||
import Header from '../shared/Header'; | ||
import App from '../App'; | ||
import indexTemplate from './indexTemplate'; | ||
|
||
const app = express(); | ||
|
||
app.use('/static', express.static('./dist/client')); | ||
|
||
app.get('/', (req, res) => { | ||
res.send(indexTemplate(ReactDOMServer.renderToString(<Header />))); | ||
res.send(indexTemplate(ReactDOMServer.renderToString(<App />))); | ||
}); | ||
|
||
app.listen(3000); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Header'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
|
||
interface ILayoutProps { | ||
children?: React.ReactNode; | ||
} | ||
|
||
export function Layout({ children }: ILayoutProps): React.ReactElement { | ||
return <article>{children}</article>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './Layout'; |
Empty file.
File renamed without changes.