Types 如何设置路径/根目录?(npm包/类型脚本)

Types 如何设置路径/根目录?(npm包/类型脚本),types,package,mapping,tsconfig,Types,Package,Mapping,Tsconfig,我正在尝试在typescript和以下设置中构建一个小组件包: 1.包(我们称之为“测试包”) 因此,在我的/src/index.ts中,我尝试了以下方法: export { default as ExampleComponent } from './components/example' 在my/src/components/ui/index.ts中: export { default as Button } from './Button' 2.我想使用“测试包”中的项目 因此,在我的项

我正在尝试在typescript和以下设置中构建一个小组件包:

1.包(我们称之为“测试包”) 因此,在我的/src/index.ts中,我尝试了以下方法:

export { default as ExampleComponent } from './components/example'
在my/src/components/ui/index.ts中:

export { default as Button } from './Button'

2.我想使用“测试包”中的项目 因此,在我的项目中我可以使用以下组件

import { ExampleComponent } from 'test-package'
import { Button } from 'test-package/dist/components/ui'
一切正常,如预期-!!但是

我真正想要的是调用我的ui组件,如:

import { Button } from 'test-package/ui'
在过去的几天里,我真的试着自己去弄清楚,所以我读了关于baseUrl和pathrootDirs的书,但说实话,我只是像一只无头鸡一样四处尝试,最终得到了:

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "declaration": true,
        "outDir": "./dist",
        "strict": true,
        "lib": [
            "dom",
            "dom.iterable",
            "esnext"
        ],
        "baseUrl": ".",
        "paths": {
            "test-package/ui": ["./dist/components/ui"]
        },
        "esModuleInterop": true,
        "allowSyntheticDefaultImports": true,
        "strictNullChecks": false,
        "forceConsistentCasingInFileNames": true,
        "moduleResolution": "node",
        "resolveJsonModule": true,
        "isolatedModules": false,
        "sourceMap": true,
        "jsx": "react",
        "noImplicitAny": false,
        "experimentalDecorators": true

    },
    "include":
        [
            "src"
        ],
    "exclude": [
        "node_modules",
        "**/__tests__/*",
        "/dist"
    ]
}
这仍然没有导致我想要的

为了完整起见,这是我的package.json:

{
  "name": "test-package",
  "version": "1.0.0",
  "description": "",
  "main": "dist/index.js",
  "types": "dist/index.d.js",
  "scripts": {
    "test": "jest --config jestconfig.json",
    "build": "rm -rf ./dist && tsc",
    "lint": "eslint --fix ./src/** --rule 'no-console: [warn, { allow: [warn, error] }]'"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/jest": "^24.0.11",
    "@types/react": "^16.8.13",
    "@typescript-eslint/eslint-plugin": "^1.6.0",
    "@typescript-eslint/parser": "^1.6.0",
    "eslint": "^5.16.0",
    "eslint-config-prettier": "^4.1.0",
    "eslint-config-standard": "^12.0.0",
    "eslint-config-standard-react": "^7.0.2",
    "eslint-plugin-import": "^2.17.2",
    "eslint-plugin-node": "^8.0.1",
    "eslint-plugin-promise": "^4.1.1",
    "eslint-plugin-react": "^7.12.4",
    "eslint-plugin-react-hooks": "^1.6.0",
    "eslint-plugin-standard": "^4.0.0",
    "jest": "^24.7.1",
    "ts-jest": "^24.0.2",
    "tslint": "^5.16.0",
    "tslint-config-prettier": "^1.18.0",
    "typescript": "^3.4.3"
  },
  "peerDependencies": {
    "react": ">= 16.8.0",
    "react-dom": ">= 16.8.0"
  },
  "files": [
    "dist/**/*"
  ]
}

{
  "name": "test-package",
  "version": "1.0.0",
  "description": "",
  "main": "dist/index.js",
  "types": "dist/index.d.js",
  "scripts": {
    "test": "jest --config jestconfig.json",
    "build": "rm -rf ./dist && tsc",
    "lint": "eslint --fix ./src/** --rule 'no-console: [warn, { allow: [warn, error] }]'"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@types/jest": "^24.0.11",
    "@types/react": "^16.8.13",
    "@typescript-eslint/eslint-plugin": "^1.6.0",
    "@typescript-eslint/parser": "^1.6.0",
    "eslint": "^5.16.0",
    "eslint-config-prettier": "^4.1.0",
    "eslint-config-standard": "^12.0.0",
    "eslint-config-standard-react": "^7.0.2",
    "eslint-plugin-import": "^2.17.2",
    "eslint-plugin-node": "^8.0.1",
    "eslint-plugin-promise": "^4.1.1",
    "eslint-plugin-react": "^7.12.4",
    "eslint-plugin-react-hooks": "^1.6.0",
    "eslint-plugin-standard": "^4.0.0",
    "jest": "^24.7.1",
    "ts-jest": "^24.0.2",
    "tslint": "^5.16.0",
    "tslint-config-prettier": "^1.18.0",
    "typescript": "^3.4.3"
  },
  "peerDependencies": {
    "react": ">= 16.8.0",
    "react-dom": ">= 16.8.0"
  },
  "files": [
    "dist/**/*"
  ]
}