2017-08-02 94 views
1

我目前的文件夹结构打字稿:多tsconfig.json问题与CommonJS的使用Node.js语言和ES6为reactjs

ts_dev 
--client 
    *components.tsx 
    *tsconfig.json 

--server 
    *server.ts 
    *tsconfig.json 
    --share 
    *utility.ts 

Node.js的服务器需要使用commonjs模块,以及es2015客户端侧面组件。我放置服务器目录下使用这两种客户服务器份额文件夹,因为它需要commonJS对Node.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引起的。我能做些什么来解决这个问题?

回答

1

我建议在文件globs中使用每个tsconfig.json文件中的include选项来限制通过每个配置文件编译的文件。

我通过使用不同的outDirs解决了我的类似问题。我认为发生在你身上的是你编译源文件两次,最后一次编译JS到es2015,覆盖第一个。换句话说,首先编译server版本,然后client版本被编译并覆盖它,因为输出将进入同一个目录。