简体   繁体   English

将.tsconfig和.tslint文件移动到其他目录

[英]Move .tsconfig and .tslint file to different directory

Inside my Angular CLI project I want to move all my config files into a new folder which I've named 'angular'. 在我的Angular CLI项目中,我想将所有配置文件移动到一个名为“ angular”的新文件夹中。 The code compiles and all npm scripts run, but I'm not getting any linting or typescript errors inside my app folder. 代码会编译,所有npm脚本都会运行,但我的app文件夹中没有任何棉绒或打字稿错误。 Here is the folder structure I am attempting: 这是我尝试的文件夹结构:

 project
    │   tslint.config.json
    │   tslint.json    
    │
    └───src
         │   
         └───angular
         │   tsconfig.app.json
         │   tslint.json
         │     
         └───app
              │   app.module.ts
              │   app.component.ts

All references inside of my angular.json file have been updated and there are no errors, but the only place the linter works is INSIDE of the 'angular' folder! 我的angular.json文件中的所有引用均已更新,并且没有错误,但是linter唯一起作用的地方是“ angular”文件夹的INSIDE! How can I change this to point to my 'app' folder? 如何更改它以指向“应用程序”文件夹? The reason I want to do this customization is to keep the files I hardly ever use out of view like this: 我要进行此自定义的原因是,使我几乎从未使用过的文件保持在这样的视线之外:

在此处输入图片说明

Based on the image of your directory structure, I'm assume that you're trying to configure VS Code specifically to give you syntax highlighting? 基于目录结构的图像,我假设您正在尝试配置VS Code,以专门为您突出显示语法?

If so, you can create a workspace specific configuration for your project, explicitly defining where VS Code can find a tslint.json configuration. 如果是这样,则可以为项目创建工作区特定的配置,显式定义VS Code在哪里可以找到tslint.json配置。 By default VS Code will look at the root of your project for your tslint configuration. 默认情况下,VS Code将为tslint配置查看项目的根目录。 In order to set your own workspace configuration you can follow the instructions from the VS Code Documentation . 为了设置自己的工作区配置,您可以按照VS Code文档中的说明进行操作。 On my mac I select the following menu items: 在我的Mac上,我选择以下菜单项:

Code -> Preferences -> Settings 代码->首选项->设置

From there I select: 从那里我选择:

the "Workspace Settings" tab and Extensions -> TSLint from the Workspace Settings sidebar 工作区设置侧栏中的“工作区设置”选项卡和扩展-> TSLint

There is a property for Config File where you can set the path to your TSLint Configuration, relative to the root of the project. Config File有一个属性,您可以在其中设置相对于项目根目录的TSLint配置的路径。 For you this would be "./src/angular/tslint.json" 对于您来说,这将是“ ./src/angular/tslint.json”

TSLint配置文件位置

In order to get console output of tslint for your project you would have to explicitly define where your tslint and tsconfig configuration files exist since they're not in the root of your project: 为了获得项目的tslint的控制台输出,您必须明确定义tslint和tsconfig配置文件的位置,因为它们不在项目的根目录中:

tslint -c src/angular/tslint.json -p src/angular/tsconfig.json

I believe VS Code is configured to use the locally installed version of Typescript by default, based on the version installed in your node_modules/typescript directory. 我认为 VS Code默认配置为使用基于node_modules / typescript目录中安装的本地版本的Typescript。 Because of this, you will continue to receive feedback on your typescript errors based on your local typescript installation, or alternatively a globally installed version of typescript. 因此,您将继续收到基于本地打字稿安装或全球安装的打字稿版本有关打字稿错误的反馈。

The typescript documentation states that: 打字稿文档指出:

The presence of a tsconfig.json file in a directory indicates that the directory is the root of a TypeScript project . 目录中存在tsconfig.json文件,表明该目录是TypeScript项目的根

So moving your tsconfig.json anywhere but the root of the project would go against the intended nature of your typescript configuration, however you can still compile you code if your tsconfig.json is not located at the root of the project by calling (or creating an npm script do the same): 因此,将tsconfig.json移到项目根目录之外的任何地方都将违反您的打字稿配置的预期性质,但是,如果您的tsconfig.json不在项目的根目录下,则可以通过调用(或创建)来编译代码一个npm脚本执行相同的操作):

tsc --project ./src/angular/tsconfig.json

Assuming you have an "include" definition in your tsconfig.json: 假设您在tsconfig.json中有一个“ include”定义:

{
  "compilerOptions": {
    /* your compiler options */
  },
  "include": [
    // source code for project is one directory up from tsconfig.json
    "../**/*",
  ]
}

暂无
暂无

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

相关问题 TSLint抱怨@Component的module.id“ tsconfig.json中未包含相应文件”(在WebStorm中) - TSLint complains @Component's module.id “Corresponding file not included in tsconfig.json” (in WebStorm) AoT编译失败-没有这样的文件或目录,lstat'tsconfig-aot.json' - AoT Compilation Failed - no such file or directory, lstat 'tsconfig-aot.json' ENOENT:在使用 angular 4 的 tsconfig.app.json 中没有这样的文件或目录? - ENOENT: no such file or directory in tsconfig.app.json using angular 4? 在架构中找不到“tsconfig”-将 tslint 迁移到 eslint (Angular v11) - 'tsConfig' is not found in schema - Migrating tslint to eslint (Angular v11) VSCode / tslint 不解析 tsconfig.json 中的路径 - VSCode / tslint does not resolve paths in tsconfig.json 错误:ENOENT:没有这样的文件或目录,lstat 'B:/...projects/admin/tsconfig.app.json' - Error: ENOENT: no such file or directory, lstat 'B:/...projects/admin/tsconfig.app.json' 修改nrwl nx项目中的tsconfig和tslint文件后需要重启VSCode才能消除错误 - VSCode needs to be restarted after modifying tsconfig and tslint files in nrwl nx projects to eliminate errors 未使用的 function 和 tsconfig.json 或 tslint 设置中的变量(角度) - Un-used function & variable in tsconfig.json or tslint setting (Angular) 如何使用tslint将黑名单导入特定文件 - How blacklist imports in a specific file with tslint 在Angular 6 Project中使用2 tslint.json文件 - Use of the 2 tslint.json file in Angular 6 Project
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM