如何针对服务器的ES6和客户端的ES5 [英] How to Target ES6 for Server and ES5 for Client

查看:100
本文介绍了如何针对服务器的ES6和客户端的ES5的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用服务器上的节点和客户端上的Angular 2创建一个项目.我想在整个项目中使用Typescript.我想将ES6作为服务器的目标,因为节点支持它,但是针对客户端的ES5.目前,我的目录结构看起来像这样.

I am creating a project with node on the server and Angular 2 on the client. I want to use Typescript across the entire project. I would like to target ES6 for the server, since node supports it, but ES5 for the client. Currently my directory structure looks something like this.

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

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

I want everything above wwwroot to target ES6, but everything inside of wwwroot to target ES5. I tried putting a second tsconfig.json inside the wwwroot folder, but that didn't seem to work. I am using Atom's autocompile feature, if that is of any relevance.

推荐答案

您可以使用babel将es6 javascript转换为所需的任何电子书风味.

You can use babel to transpile es6 javascript to whatever flavor of ecmascript you desire.

http://babeljs.io/

这篇关于如何针对服务器的ES6和客户端的ES5的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆