aha*_*tiz 6 express typescript reactjs server-side-rendering create-react-app
I have a project built by create-react-app typescript (tsx files).
我现在想把这个项目做成SSR,但是我不知道如何开始。
在使用本文之后的打字稿之前,我能够进行 SSR
如果你能给我一个指南,不胜感激
经过8个小时的努力,我解决了这个问题。
您不能将react的tsconfig文件用于服务器。
我必须制作一个新的配置文件。(服务器.tsconfig.json)
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"*": ["*", "./src/@types/*"]
},
"outDir": "./dist",
"target": "es5",
"typeRoots": ["./src/@types", "./node_modules/@types"],
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noImplicitAny": false,
"moduleResolution": "node",
"strictNullChecks": false,
"jsx": "react",
"noEmit": true
},
"exclude": ["node_modules"]
}
Run Code Online (Sandbox Code Playgroud)
并在运行 ts-node 时指示此配置
ts-node --project server.tsconfig.json --require tsconfig-paths/register server/index.js
Run Code Online (Sandbox Code Playgroud)
如果您使用自定义类型,则必须在服务器文件上添加类型引用
/// <reference path="../src/@types/global.d.ts" />
Run Code Online (Sandbox Code Playgroud)
我希望这能节省您的时间
| 归档时间: |
|
| 查看次数: |
2482 次 |
| 最近记录: |