构建具有所需文件结构的NPM软件包



我创建了一个简单的打字稿项目来导出枚举,我成功地编译了该项目。tsconfig.json and package.json。我使用npm命令将其包装,并将NPM发布。我将相同的软件包安装到一个新项目中,并将其导入代码

import Numbers = require('@hk18/export/dist');

我想像

import Numbers = require('@hk18/export');

它包括包装中的dest文件夹,为什么?

{   "compilerOptions": {
    "module": "commonjs",
    "target": "es5",
    "outDir": "./dist",
    "moduleResolution": "node",
    "declaration": true   },   "include": [
    "src/**/*.ts",
    "index.ts"   ] }
___________________________________________________________
{   "name": "@hk18/export",   "version": "2.0.0",   "description": "test project to create npm package",   "main": "index.js",   "scripts": {
    "build": "tsc",
    "build:watch": "tsc --watch",
    "lint": "tslint --project "./tsconfig.json"",
    "test": "mocha --reporter spec",
    "docs": "typedoc --out docs src",
    "gh-pages": "rimraf docs && npm run docs && gh-pages -d docs"   },   "author": "HK",   "license": "ISC", }

您的软件包。JSON缺少types条目。它应该匹配您的main条目。另外,您的主体也应指向dist文件夹。

固定版本

"main": "./dist/index.js",
"types" : "./dist/index.d.ts",

最新更新