node.js - 如何为服务器定位 ES6 并为客户端定位 ES5

标签 node.js angular typescript ecmascript-6 tsconfig

我正在创建一个项目,该项目在服务器上使用 Node ,在客户端上使用 Angular 2。我想在整个项目中使用 Typescript。我想为服务器定位 ES6,因为 Node 支持它,但为客户端定位 ES5。目前我的目录结构看起来像这样。

├── app.js
├── something.js
├── tsconfig.json
├── wwwroot
│   ├── index.html
│   ├── main.ts
│   ├── components
│   │   ├── mycomponent.ts

我希望 wwwroot 之上的所有内容都以 ES6 为目标,而 wwwroot 内的所有内容都以 ES5 为目标。我尝试将第二个 tsconfig.json 放入 wwwroot 文件夹中,但这似乎不起作用。我正在使用 Atom 的自动编译功能,如果它有任何相关性的话。

最佳答案

您可以使用 babel 将 es6 javascript 转换为您想要的任何 ecmascript 风格。

http://babeljs.io/

关于node.js - 如何为服务器定位 ES6 并为客户端定位 ES5,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40479782/

相关文章:

angular - 如何在 dxdatagrid 中动态创建带有数据类型的 dxi 列?

javascript - 什么构成了 React 中 ref 的适当使用

typescript - 为什么某些基本类型在 TypeScript 中不能传递赋值——它们是否按预期运行?

node.js - 为 LocomotiveJS 应用程序(NodeJS/Express)实现/强制使用 SSL

javascript - Node js mysql查询在第二次执行时出错

node.js - http-server-usr/bin/env : node : no such file or directory

angular - 在 Ionic 2 中使用自定义数据组件

Angular 如何使 [formControl] 成为可选字段

node.js - Express 无法从后面读取未定义的属性 'name'

node.js - 如果请求失败,axios(或 Node )就会卡住