如何在Angular 5+中使用未编译的TypeScript导入repo(并排除.spec.ts文件) [英] How to import repo with uncompiled TypeScript in Angular 5+ (and exclude .spec.ts files)

查看:110
本文介绍了如何在Angular 5+中使用未编译的TypeScript导入repo(并排除.spec.ts文件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近升级到Angular 5.x不允许未编译的TypeScript从node_modules存储库导入.看来解决方法是通过"include": ["node_modules/example/**/*.ts"]使用tsconfig.json包括.ts文件.但是,其中包括会导致错误的.spec.ts文件.

A recent upgrade to Angular 5.x is not allowing uncompiled TypeScript to import from a node_modules repo. It looks like the workaround is to include the .ts files using tsconfig.json via "include": ["node_modules/example/**/*.ts"]; however, this includes .spec.ts files, which are causing errors.

稍微回溯一下,如果您的存储库未编译,则会出现如下错误:

Backtracking a bit, if your repo is uncompiled, you get an error that looks like:

ERROR in ./node_modules/example/lib/core/example.ts
Module build failed: Error: /Users/example/Work/example/example/node_modules/example/lib/core/example.ts is missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
The missing file seems to be part of a third party library. TS files in published libraries are often a sign of a badly packaged library. Please open an issue in the library repository to alert its author and ask them to package the library using the Angular Package Format (goo.gl/jB3GVv).
    at AngularCompilerPlugin.getCompiledFile (/Users/example/Work/example/example/node_modules/@angular/cli/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:656:23)
    at plugin.done.then (/Users/example/Work/example/example/node_modules/@angular/cli/node_modules/@ngtools/webpack/src/loader.js:467:39)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
 @ ./lib/visualization/visualization-widget/visualization-widget/visualization-widget.component.ts 25:24-79
 @ ./lib/visualization/visualization-widget/visualization-widget.module.ts
 @ ./lib/visualization/visualization.module.ts
 @ ./lib/example.module.ts
 @ ./src/demo-app/app.module.ts
 @ ./src/main.ts
 @ multi webpack-dev-server/client?http://0.0.0.0:0 ./src/main.ts

我了解未编译的TS不会像以前那样导入,因为无法控制将哪个编译器用于库.但是,这对我们没有影响,因为它在内部仓库中,我们可以对此进行控制.因此,导入未编译的TS可以节省我们一个步骤(并有可能无意中省略了此步骤).

I understand uncompiled TS wont import as it used to, because there is no control over which compiler is used for a library. However, this is of no consequence for us, because it is in an internal repo where we DO have control over that. So importing uncompiled TS saves us a step (and potential for unintentionally omitting this step).

问题是我们不确定如何包含.ts文件和排除 .spec.ts文件.

The problem is that we are not sure how to include .ts files and exclude .spec.ts files.

tsconfig.json中,我们有:

  "include": ["node_modules/example/**/*.ts"],
  "exclude": ["node_modules/example/**/*.spec.ts"],

这不起作用.据我了解,.spec.ts文件仍包含在内,因为第一条include规则胜过"第二条exclude规则.

This does not work. .spec.ts files are still included as, as I understand, the first include rule 'wins' over the second exclude rule.

我们如何导入.ts文件并排除.spec.ts文件?

How can we import .ts files and exclude .spec.ts files?

这是今天早些时候我的问题:如何在tsconfig.json中排除以'.spec.ts'结尾的文件 这是有关此问题的主题: https://github.com/angular/angular-cli/issues/8284

Here is my question from earlier today: How to exclude files ending in '.spec.ts' in tsconfig.json Here's a thread about this issue: https://github.com/angular/angular-cli/issues/8284

推荐答案

打开tsconfig.json,然后更改为此

open your tsconfig.json, and change to this

{
  ...
  "compilerOptions": {
   ...
  },      
  "include": [
    "./src",
    "node_modules/example"
  ],
  "exclude" : ...
}

这篇关于如何在Angular 5+中使用未编译的TypeScript导入repo(并排除.spec.ts文件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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