简体   繁体   English

Play中的TypeScript模块分辨率如何工作?

[英]How does TypeScript module resolution in Play work?

I'd like to use Angular 2 with TypeScript in my Play project. 我想在我的Play项目中使用带有TypeScript的Angular 2。 I'm using the sbt-typescript plugin and the angular2 WebJAR. 我正在使用sbt-typescript插件angular2 WebJAR。 When Play extracts the WebJAR, it puts it in target/web/public/main/lib/angular2 . 当Play提取WebJAR时,它将它放在target/web/public/main/lib/angular2 What I should be able to do in my app/assets/js/components/test.ts file is something like 我应该能够在app/assets/js/components/test.ts文件中app/assets/js/components/test.ts什么

import {Component} from 'angular2/core';

but tsc is unable to resolve that, and I don't see any setting to tell it where to look. 但是tsc无法解决这个问题,我没有看到任何设置告诉它在哪里看。

Is this even currently possible? 这甚至可能吗? Would having a child project for just the TypeScript stuff make it easier? 只有TypeScript的东西让孩子项目变得容易吗?

It is in fact currently possible to resolve Javascript/Typescript modules from your webjars dependencies. 事实上,这目前可以从你的webjars依赖解决的JavaScript /打字稿模块。 I've created a demo Play application that shows how. 我已经创建了一个演示Play应用程序来展示如何。
See https://github.com/joost-de-vries/play-angular2-typescript 请参阅https://github.com/joost-de-vries/play-angular2-typescript

It uses a different sbt-typescript plugin that customises the module resolution. 它使用不同的sbt-typescript插件来定制模块分辨率。 Thus working around the shortcoming that bpervan mentions. 因此解决了bpervan提到的缺点。

I've struggled with same issue for a while, until I found that, currently, it is not possible. 我已经在同一个问题上挣扎了一段时间,直到我发现,目前,这是不可能的。

See: https://github.com/ArpNetworking/sbt-typescript/issues/33 请参阅: https//github.com/ArpNetworking/sbt-typescript/issues/33

Current version of TypeScript transpiler does not support custom paths for module resolution, and, as it seems, it won't until version 2.0. 当前版本的TypeScript转换器不支持模块解析的自定义路径,并且看起来,直到2.0版本才会这样。 You can check it out on official TypeScript Roadmap on their github repo (I'd love to paste link here, but SO doesn't allow me) 你可以在他们的github repo上的官方TypeScript路线图上查看它(我想在这里粘贴链接,但是SO不允许我)

I guess, for now, that the only way to use angular2 with TypeScript in Play project is to let npm resolve dependencies for tsc. 我想,现在,在Play项目中使用angular2和TypeScript的唯一方法是让npm解析tsc的依赖关系。 You may still use WebJars in Scala templates (SuperManitu left a link for his template in 1 , check it out (again, can't paste link, sorry)) 您仍然可以在Scala模板中使用WebJars(SuperManitu在1中留下了他的模板的链接,检查出来(再次,无法粘贴链接,抱歉))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM