具有纱线工作区和打字稿的本地包和有角度的lib

时间:2019-12-19 14:22:27

标签: angular typescript yarn angular-library ng-build

我正在尝试,首先想到的是一个简单的任务,在本地构建一个包并将其导入到我的角度库中。我正在使用yarn工作区(或更有效的尝试)来模拟链接程序包,并将其用作import { foo } from "@bar"

这是到目前为止我得到的: 我的项目具有这种结构:

/packages
  -- /angular-lib
     -- /projects/namespace/libName/**/*
  -- /parser/src/*

漂亮的标准库和解析器包

解析器tsconfig

{
    "compilerOptions": {
        "baseUrl": "src",
        "sourceMap": true,
        "declaration": true,
        "module": "commonjs",
        "moduleResolution": "node",
        "outDir": "dist",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "declarationDir": "typings",
        "target": "es2017",
        "forceConsistentCasingInFileNames": true,
        "strict": true,
        "strictPropertyInitialization": false,
        "noImplicitReturns": true,
        "noUnusedLocals": true,
        "noUnusedParameters": true,
        "preserveConstEnums": true,
        "typeRoots": ["node_modules/@types"],
        "composite": true
    },
    "include": ["src/index.ts", "src/parser.ts", "src/interfaces.ts"],
    "exclude": ["node_modules", "**/__tests__/*", "src/*.spec.ts"]
}

在这里,我正在使用Composite标志从angular-lib引用它,并使用tsc -b构建解析器

libs tsconfig

{
    "compileOnSave": false,
    "compilerOptions": {
        "baseUrl": "./",
        "outDir": "./dist/",
        "sourceMap": true,
        "declaration": false,
        "downlevelIteration": true,
        "experimentalDecorators": true,
        "module": "esnext",
        "moduleResolution": "node",
        "importHelpers": true,
        "target": "es2015",
        "typeRoots": ["node_modules/@types"],
        "lib": ["es2018", "dom"],
        "paths": {
            "@namespace/libName": ["dist/namespace/libName"],
            "@namespace/libName/*": ["dist/namespace/libName/*"]
            "@namespace/parser": ["../parser"],                **1**
        }
    },
    "angularCompilerOptions": {
        "fullTemplateTypeCheck": true,
        "strictInjectionParameters": true
    },
    "references": [{ "path": "../parser" }]                    **2**
}

稍后我在此处为我的问题标记了两行。

actualLib / src中的tsconfig.lib.json是标准

在libName / package.json中有一个"@namespace/parser": 0.0.1 peerDependency 还有package.json。 我另外添加了"@namespace/parser": 0.0.1作为依赖项<-我不确定。这有必要吗?

现在我的问题是: 当我运行ng build时,编译器会告诉我

ERROR: error TS6059: File 'C:/*/packages/parser/src/index.ts' is not under 'rootDir' 'C:\*\packages\libName\projects\namespace\actualLib\src'. 'rootDir' is expected to contain all source files.

An unhandled exception occurred: error TS6059: File 'C:/*/packages/parser/src/index.ts' is not under 'rootDir' 'C:\*\libName\projects\namespace\actualLib\src'. 'rootDir' is expected to contain all source files.

还将我在import {} from "@namespace/parser中的packages/libName/projects/namespace/actualLib/src/lib/component.ts标记为“找不到模块”

我猜问题出在我的libName tsconfig上,我在其中标记了 1 2 。我什至需要引用工作空间吗?

我正确使用纱线工作区吗?当我打电话给yarn workspaces info时,它会产生

{
  "@namespace/parser": {
    "location": "packages/parser",
    "workspaceDependencies": [],
    "mismatchedWorkspaceDependencies": []
  },
  "libName": {
    "location": "packages/libName",
    "workspaceDependencies": [
      "@namespace/parser"
    ],
    "mismatchedWorkspaceDependencies": []
  },
  "@namespace/actualLib": {
    "location": "packages/libName/projects/namespace/actualLib",
    "workspaceDependencies": [],
    "mismatchedWorkspaceDependencies": []
  }
}

0 个答案:

没有答案