代码之家  ›  专栏  ›  技术社区  ›  Liero

如何将typescript定义文件添加到源代码管理中?

  •  0
  • Liero  · 技术社区  · 6 年前

    我有简单的ASP.NET核心Web应用程序,在那里我安装了使用libman的javascript库。

    我想使用typescript,所以我已经为使用NPM的库安装了typescript定义文件,例如:

    npm install @types/jquery --save-dev
    npm install @types/bootstrap --save-dev
    

    我想将.d.ts文件添加到源代码管理中,这样其他开发人员就不必依赖于NPM了——这是libman的目的,不是吗?

    /默认情况下,忽略.gitignore中的node_modules文件夹。

    如何包含类型脚本定义文件?

    2 回复  |  直到 6 年前
        1
  •  1
  •   itminus    6 年前

    因为您已经安装了javascript库, LibMan ,您可以简单地重用 利伯曼 也要安装定义:

    libman install @types/jquery -p unpkg
    libman install @types/bootstrap -p unpkg
    

    默认路径为 libs/@types 伊米尔

    lib/
        @types/
            bootstrap/
                index.d.ts
                ...
            jquery/
                index.d.ts
                ...
    

    我创建了一个 tsconfig.json 并配置路径映射以加载模块,如下所示:

    {
        "compilerOptions": {
            "baseUrl": ".",
            "paths": {
                "jquery": ["lib/@types/jquery"] ,
                "bootstrap":["lib/@types/bootstrap"]
            }
          }
    }
    

    现在我们可以从typescript中获益:

    enter image description here

    [更新]

    对于aspnet-core项目,默认路径为: wwwroot/lib/@types 如果我们有 TSOCONT.JSON 在项目目录下(在 *.csproj 项目文件),我们需要将路径更改为:

    {
        "compilerOptions": {
            "baseUrl": ".",
            "paths": {
                "jquery": ["wwwroot/lib/@types/jquery"] ,
                "bootstrap":["wwwroot/lib/@types/bootstrap"]
            }
          }
    }
    

    enter image description here

        2
  •  0
  •   kitsu.eb    6 年前

    对于那些只想自己输入的人:由 libman install @types/jquery -p unpkg

    {
        "provider": "unpkg",
        "library": "@types/jquery@3.3.29",
        "destination": "wwwroot/js/lib/@types/jquery"
    }
    

    (注:我有一个 libman.json 文件,并将其添加到 "libraries" 数组)

    推荐文章