从导入路径中删除 dist

Remove dist from the import path

我写了一个小库

lib/index.ts 我有这个代码

export default function hello() {
    return 'world'
}

package.json

{
  "name": "@org/library",
  "author": "Org name",
  "version": "1.0.8",
  "main": "dist/index.js",
  "license": "MIT",
  "devDependencies": {
    "typescript": "^4.4.3"
    ...
  },
  "scripts": {
    "build": "tsc",
    "clear": "rimraf dist/"
  }
}

tsconfig.json

{
  "exclude": ["lib/**/*.spec.tsx", "lib/**/*.stories.tsx", "lib/**/*.styles.tsx", "dist/**/*"],
  "compilerOptions": {
    "skipLibCheck": true,
    "target": "es6",
    "module": "es6",
    "lib": ["es6", "dom"],
    "jsx": "react",
    "declaration": true,
    "declarationMap": true,
    "sourceMap": true,
    "outDir": "dist",
    "rootDirs": ["lib"],
    "strict": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true
  }
}

但是当我去另一个项目使用时,我不得不在路径上使用dist导入

为什么我必须这样导入

import hello from '@org/library/dist'

而不是

import hello from '@org/library/dist'

我需要做什么才能从导入路径中删除 dist

我以自定义 Makefile 结尾

.PHONY: build clean lint publish test

build:
    npm run build

clean:
    npm run clean

lint:
    npm run lint

test:
    npm run test

publish: clean lint test build
    cp package.json dist
    npm publish dist