【问题标题】:Build npm package with desired file structure构建具有所需文件结构的 npm 包
【发布时间】:2019-05-08 12:22:28
【问题描述】:

我创建了一个简单的 typescript 项目来导出 ENUMS,我成功编译了该项目。 tsconfig.json 和 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", }

【问题讨论】:

    标签: node.js typescript npm


    【解决方案1】:

    您的package.json is missing a types entry。它应该与您的 main 条目匹配。此外,您的 main 也应该指向 dist 文件夹。

    固定版本

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

    【讨论】:

      猜你喜欢
      • 2013-08-11
      • 2020-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多