typescript 编译器包不包含依赖项 [英] typescript compiler bundle doesn't contain dependencies

查看:65
本文介绍了typescript 编译器包不包含依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将我的 angular2 应用程序与带有 tsconfig.js 的打字稿编译器捆绑在一起:

I try to bundle my angular2 application with the typescript compiler with a tsconfig.js like this:

{
  "compilerOptions": {
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [ "es2015", "dom" ],
    "noImplicitAny": true,
    "suppressImplicitAnyIndexErrors": true,
    "outFile": "bundle.js"
  }
}

它创建了一个 bundle.js 但没有任何角度依赖.它只包含我自己的组件和打字稿文件.知道如何告诉编译器将引用的依赖项也包含到包中吗?

It creates a bundle.js but without any angular-depenencies. It only includes my own components and typescript files. Any idea how I can tell the compiler to include the referenced dependencies as well into the bundle?

推荐答案

您没有提到什么您想要捆绑;Angular 2 框架本身或其类型定义文件.我认为前者是正确的.

You didn't mention what exactly you want to bundle; the Angular 2 framework itself, or its type definition files only. I presume the former is correct.

TypeScript 编译器不会为您捆绑您的应用,它只会将 TS 代码编译为 JS.
也许混淆在于 outFile 选项,它 声明:

The TypeScript compiler won't bundle your app for you, it will just compile TS code to JS.
Perhaps the confusion lies in the outFile option, which is stated to:

连接输出到单个文件 […]

Concatenate and emit output to single file […]

…但仅适用于您自己的应用程序中的 TS 输入文件.

… but applies only to TS input files in your own application.

为了在您的应用程序中包含 Angular 2 源文件,您必须使用 bundler,例如 webpack.

In order to include the Angular 2 source files with your application, you'd have to use a bundler such as webpack.

这篇关于typescript 编译器包不包含依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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