我已經在 NPM 上發布了一個 TypeScript 庫。在 GitHub 上,dist(鏈接到存盤庫檔案夾)目錄包含所有已編譯的 JavaScript 和 d.ts 檔案。但是,當運行npm i <my_package>結果是一個dist包含僅包含 的檔案夾的模塊時index.js,該src檔案夾仍然存在 TypeScript 檔案。dist/src在已安裝的包中找不到該檔案夾??及其 JavaScript 和 d.ts 檔案,因此在 Vanilla JavaScript 專案中無法識別或鍵入我的模塊。
庫 tsconfig.json:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": true,
"outDir": "./dist",
"strict": true,
},
"exclude": [
"node_modules/",
"dist/"
]
}
庫包.json
{
"name": "easy-trivia",
"version": "2.0.3",
"description": "A wrapper for the Open Trivia Database API. Built with TypeScript, works with VanillaJS.",
"keywords": [
"trivia",
"games",
"fun",
"api",
"easy",
"typescript",
"small",
"quiz",
"opentriviadatabase",
"opentdb",
"opentriviadb"
],
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"build": "tsc",
"prettier": "npm run build && prettier -w src/",
"prepublish": "npm run prep",
"exec": "npm run build && node .",
"test": "npm run build && npx jest",
"prep": "npm run build && npm run test && npm run prettier"
},
"files": [
"src",
"typings"
],
"repository": {
"type": "git",
"url": "git https://github.com/Elitezen/easy-trivia.git"
},
"author": "Elitezen",
"license": "ISC",
"bugs": {
"url": "https://github.com/Elitezen/easy-trivia/issues"
},
"homepage": "https://github.com/Elitezen/easy-trivia#readme",
"devDependencies": {
"@types/jest": "^27.0.3",
"@types/node": "^16.11.7",
"jest": "^27.5.1",
"nodemon": "^2.0.12",
"prettier": "2.4.1",
"ts-jest": "^27.1.3"
},
"engines": {
"node": ">=14.0.0",
"npm": ">=7.0.0"
}
}
uj5u.com熱心網友回復:
要發布這些型別,您需要dist在. 僅在其中指定檔案實際上不會包含它。因為這是不同的,因為它會自動包含指定的檔案。根據npm package.json 檔案:filespackage.jsontypesmain
無論設定如何,始終包含某些檔案:
- 包.json
- 自述檔案
- 執照/執照
- “主”欄位中的檔案
要輕松驗證包含哪些檔案,npm pack --dry-run非常方便。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/450217.html
標籤:javascript 节点.js 打字稿 npm npm-安装
