简体   繁体   English

webpack会将Angular2打字稿编译为javascript吗?

[英]Does webpack compile Angular2 typescript to javascript?

I have followed Angular2 tutorial to add webpack. 我已经按照Angular2教程添加了webpack。 I get following errors eg: 我得到以下错误,例如:

    [default] D:\...\node_modules\@angular\core\src\util\decorators.d.ts:11:4 
Property 'extends' of type 'Type<any> | undefined' is not assignable to string index type 'Function | any[] | Type<any>'.[default] D:\...\node_modules\@angular\platform-browser\src\dom\dom_renderer.d.ts:25:21 

It seems that webpack tries to compile the whole angular stuff that I reference, which seems a bit too much. 似乎webpack试图编译我引用的整个有角度的东西,这似乎有点过多。

As far as I understand there are already built angular js files that we can use instead of compiling angular (and all other libraries I suppose) each time? 据我了解,已经有构建的角度js文件,我们可以使用它们来代替每次编译角度(以及我假设的所有其他库)? Is it possible/reasonable to do so? 有可能这样做吗?

It does whatever you include and tell it to do. 它会执行您包含的所有内容,并告诉它要执行的操作。

Eg if you directly import an angular typescript file from your main module (or anything that is included from it) and if you have a loader for typescript configured it will transpile this typescript to javascript. 例如,如果您直接从您的主模块(或其中包含的任何内容)中导入一个有角度的打字稿文件,并且如果您为打字稿配置了加载程序,它将将该打字稿转换为javascript。

However if you import a javascript module (like with import { Component } from '@angular/core' . No trailing .ts ) it will include that and not transpile anything.; 但是,如果您导入一个javascript模块(例如import { Component } from '@angular/core' 。没有尾随.ts ),它将包含该模块并且不进行任何转换。

Your error could also be some problem with type definitions. 您的错误也可能是类型定义出现问题。 Which means it already uses the javascript version, but there's somehow a problem with the configured/referenced typescript typings ( .d.ts is mentioned) which means the typescript compiler will report an error. 这意味着它已经使用了javascript版本,但是以某种方式配置/引用的打字稿.d.ts存在问题(提到了.d.ts ),这意味着打字稿编译器将报告错误。

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

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