【问题标题】:Remove dist from the import path从导入路径中删除 dist
【发布时间】:2021-11-20 11:25:43
【问题描述】:

我写了一个小库

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

【问题讨论】:

标签: javascript typescript npm tsconfig tsc


【解决方案1】:

我以自定义 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-26
    • 2013-05-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多