【发布时间】:2018-01-09 09:02:14
【问题描述】:
我当前的 typescript 文件夹结构:
ts_dev
--client
*components.tsx
*tsconfig.json
--server
*server.ts
*tsconfig.json
--share
*utility.ts
Node.js 服务器需要使用commonjs模块,客户端端组件需要使用es2015。我将 client 和 server 使用的 share 文件夹放在 server 目录下,因为它需要commonJS节点.js。
tsconfig.json:
{
"compilerOptions": {
"module": "commonJS",
"target": "es2015",
"moduleResolution": "node",
"outDir": "../../src",
"lib": ["es6", "dom"],
"types": ["reflect-metadata","system"],
"jsx": "react"
},
"exclude": [
"node_modules",
]
}
客户端中的tsconfig.json:
{
"compilerOptions": {
"module": "es2015",
"target": "es2015",
"moduleResolution": "node",
"outDir": "../../src",
"lib": ["es6", "dom"],
"types": ["reflect-metadata","system"],
"jsx": "react"
},
"exclude": [
"node_modules",
]
}
但是我发现share 中的脚本总是在 es6(使用导出、导入等)而不是 commonJS 中编译,这会破坏我的服务器。我怀疑这是由client 中的 tsconfig 引起的。我可以做些什么来解决这个问题?
【问题讨论】:
标签: node.js reactjs typescript typescript2.0 tsconfig