我一直在尝试使用typescript构建一个create-react-app + Express全栈应用。但是我不知道如何将服务器文件编译到构建文件夹。我为服务器和create-react-app有单独的tsconfig文件。
我希望文件进入build/server
。服务器ts文件位于./server
中,React位于./src
中。
tsconfig.json(由create-react-app提供):
{ "compilerOptions":
{ "target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve" },
"include": ["src"]}
tsconfig.server.json:
{ "extends": "./tsconfig.json",
"compilerOptions":
{ "module": "commonjs",
"outDir": "build/server" },
"include": ["server"]}
我正在尝试与之建立联系
tsc -p tsconfig.server.json
我没有错误,但是什么也没发生。
答案 0 :(得分:0)
我弄清楚出了什么问题。
Create-react-app提供“ noEmit”:true作为配置选项,这意味着更改将不会提交到build文件夹。在服务器tsconfig.json中指定“ noEmit”:false解决了该问题。