-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* chore: use pnpm workspace * ci: use corepack pnpm * ci: fix ci * refactor(examples/express): update express example convert jsx to tsx, improve types, modify compose file for production, add esbuild config for client-entry bundling, improve tsconfigs, update deps * refactor(examples/next): improve next example, adapt for production, add compose file * refactor(lib): naming and formatting * chore(lib): update and clean up deps, improve scripts and tsconfig * refactor(lib/withESI): improve types, add safeRequireServer, isClient and isServer functions * chore: improve configs, dockerfile, ci and pnpm workspace * docs(examples): update examples readme * perf(docker): optimize dockerfile with a base-deps stage, rename stages * docs(readme.md): small adjustments * chore(package.json): add funding field * chore(package.json): add Github sponsor funding entry --------- Co-authored-by: JH <je.hu@pm.me>
- Loading branch information
Showing
63 changed files
with
9,061 additions
and
7,417 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
node_modules | ||
Dockerfile | ||
compose.yaml | ||
.git | ||
.gitignore | ||
*.md | ||
dist | ||
.github | ||
.vscode | ||
.next | ||
lib/lib |
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 @@ | ||
# EditorConfig is awesome: https://EditorConfig.org | ||
|
||
# top-most EditorConfig file | ||
root = true | ||
|
||
[*] | ||
end_of_line = lf | ||
insert_final_newline = true | ||
indent_style = space | ||
indent_size = 2 | ||
charset = utf-8 | ||
trim_trailing_whitespace = true |
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 |
---|---|---|
@@ -1,5 +1,37 @@ | ||
/lib | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
node_modules | ||
/coverage | ||
yarn-error.log | ||
.pnp | ||
.pnp.js | ||
.pnpm-store | ||
|
||
# testing | ||
coverage | ||
|
||
# next.js | ||
.next/ | ||
out/ | ||
|
||
# production | ||
build | ||
dist | ||
lib/lib | ||
|
||
# misc | ||
.DS_Store | ||
*.pem | ||
|
||
# debug | ||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* | ||
|
||
# local env files | ||
.env*.local | ||
|
||
# vercel | ||
.vercel | ||
|
||
# typescript | ||
*.tsbuildinfo |
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 @@ | ||
link-workspace-packages=false |
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 |
---|---|---|
|
@@ -3,3 +3,5 @@ | |
**/.hg | ||
**/node_modules | ||
**/.next | ||
**/dist | ||
/lib/lib |
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,7 +1,3 @@ | ||
{ | ||
"printWidth": 80, | ||
"endOfLine": "auto", | ||
"semi": true, | ||
"singleQuote": false, | ||
"trailingComma": "none" | ||
"trailingComma": "es5" | ||
} |
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,7 @@ | ||
{ | ||
"recommendations": [ | ||
"dbaeumer.vscode-eslint", | ||
"esbenp.prettier-vscode", | ||
"orta.vscode-jest" | ||
] | ||
} |
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,20 @@ | ||
{ | ||
"jest.outputConfig": { | ||
"clearOnRun": "none", | ||
"revealOn": "demand", | ||
"revealWithFocus": "none" | ||
}, | ||
"testing.openTesting": "neverOpen", | ||
"eslint.workingDirectories": ["lib/", "examples/express/", "examples/next/"], | ||
"editor.codeActionsOnSave": { | ||
"source.eslint.fixAll": "explicit" | ||
}, | ||
"editor.formatOnSave": true, | ||
"editor.defaultFormatter": "esbenp.prettier-vscode", | ||
"eslint.validate": [ | ||
"javascript", | ||
"javascriptreact", | ||
"typescript", | ||
"typescriptreact" | ||
] | ||
} |
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,77 @@ | ||
FROM node:20-slim AS base | ||
ENV PNPM_HOME="/pnpm" | ||
ENV PATH="$PNPM_HOME:$PATH" | ||
RUN corepack enable pnpm | ||
|
||
FROM base AS base-deps | ||
WORKDIR /home/node/repo | ||
|
||
COPY ./package.json ./pnpm-*.yaml ./ | ||
COPY ./lib/package.json ./lib/ | ||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile | ||
|
||
|
||
|
||
# Express | ||
FROM base AS express-deps | ||
WORKDIR /home/node/repo | ||
COPY --from=base-deps /home/node/repo ./ | ||
|
||
COPY ./examples/express/package.json ./examples/express/ | ||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile | ||
|
||
|
||
FROM base AS express-build | ||
WORKDIR /home/node/repo | ||
COPY --from=express-deps /home/node/repo ./ | ||
COPY . /home/node/repo | ||
|
||
RUN pnpm --filter !esi-next run build | ||
RUN pnpm deploy --filter esi-express --prod /home/node/esi-express | ||
|
||
FROM base AS express-prod | ||
COPY --from=express-build /home/node/esi-express /home/node/esi-express | ||
WORKDIR /home/node/esi-express | ||
USER node | ||
EXPOSE 3000 | ||
CMD [ "node", "dist/server.js" ] | ||
|
||
|
||
|
||
# Nextjs | ||
FROM base AS next-deps | ||
WORKDIR /home/node/repo | ||
COPY --from=base-deps /home/node/repo ./ | ||
|
||
COPY ./examples/next/package.json ./examples/next/ | ||
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile | ||
|
||
|
||
FROM base AS next-build | ||
WORKDIR /home/node/repo | ||
COPY --from=next-deps /home/node/repo ./ | ||
COPY . /home/node/repo | ||
|
||
ENV NEXT_TELEMETRY_DISABLED 1 | ||
RUN pnpm --filter !esi-express run build | ||
RUN pnpm deploy --filter esi-next --prod /home/node/esi-next | ||
|
||
|
||
FROM base AS next-prod | ||
WORKDIR /home/node/esi-next | ||
|
||
ENV NODE_ENV production | ||
ENV NEXT_TELEMETRY_DISABLED 1 | ||
|
||
# Set the correct permission for prerender cache | ||
RUN mkdir .next | ||
RUN chown node:node .next | ||
COPY --from=next-build --chown=node:node /home/node/esi-next/public ./public | ||
COPY --from=next-build --chown=node:node /home/node/esi-next/node_modules ./node_modules | ||
COPY --from=next-build --chown=node:node /home/node/esi-next/.next/standalone ./ | ||
COPY --from=next-build --chown=node:node /home/node/esi-next/dist ./dist | ||
COPY --from=next-build --chown=node:node /home/node/esi-next/.next/static ./.next/static | ||
|
||
USER node | ||
EXPOSE 3000 | ||
CMD [ "node", "dist/server.js" ] |
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 |
---|---|---|
@@ -1,19 +1,11 @@ | ||
# Custom server example with Express, Nodemon, Varnish, and react-esi | ||
# Custom server example with Express, Varnish, and react-esi | ||
|
||
This example demonstrates how to set up an [Express](https://expressjs.com/) server using JavaScript and how to leverage [Nodemon](https://nodemon.io/) for live reloading of the server code. Additionally, it introduces caching optimization with a [Varnish](https://varnish-cache.org/intro/) server and the `react-esi` library using `esi:include` tags. | ||
This example demonstrates how to set up an [Express](https://expressjs.com/) server using Typescript. Additionally, it introduces caching optimization with a [Varnish](https://varnish-cache.org/intro/) server and the `react-esi` library using `esi:include` tags. | ||
|
||
|
||
The server entry point is `server.jsx` in development and `dist/server.js` in production. | ||
|
||
## Deploy your own | ||
|
||
Deploy the example using [Vercel](https://vercel.com) or preview live with [StackBlitz](https://stackblitz.com/github/dunglas/react-esi/tree/main/examples/express) | ||
|
||
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/dunglas/react-esi/tree/main/examples/express) | ||
The server entry point is `server.tsx` in development and `dist/server.js` in production. | ||
|
||
## How to use | ||
|
||
1. Clone this repository. | ||
2. Navigate to the examples/express folder. | ||
3. Run `yarn install` to install the dependencies. | ||
4. Use `docker compose` to run the example. | ||
3. Use `docker compose up -d` to run the example. |
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,14 @@ | ||
import * as esbuild from "esbuild"; | ||
|
||
await esbuild.build({ | ||
entryPoints: ["src/entry-client.tsx"], | ||
outfile: "dist/entry-client.js", | ||
define: { | ||
"process.env.NODE_ENV": '"production"', | ||
}, | ||
target: ["es6"], | ||
bundle: true, | ||
treeShaking: true, | ||
minify: true, | ||
keepNames: true, | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.