npmpublish 只发布index.js并排除其他所有内容

Edw*_*oto 4 javascript npm typescript npm-publish tsdx

问题

我正在尝试在 npm 中发布我自己的 SDK。当我尝试安装软件包时,我的 dist 文件夹仅显示 index.js

代码:

这是我的package.json文件。它已经包含主文件和文件,https://docs.npmjs.com/cli/v8/using-npm/scripts

{
  "version": "0.1.4",
  "license": "MIT",
  "main": "dist/index.js",
  "typings": "dist/index.d.ts",
  "files": [
    "dist"
  ],
  "engines": {
    "node": ">=10"
  },
  "scripts": {
    "start": "tsdx watch",
    "build": "tsdx build",
    "test": "tsdx test --passWithNoTests",
    "lint": "tsdx lint",
    "prepare": "tsdx build",
    "prepublish": "tsdx build",
    "size": "size-limit",
    "analyze": "size-limit --why"
  },
  "peerDependencies": {
    "react": ">=16"
  },
  "husky": {
    "hooks": {
      "pre-commit": "tsdx lint"
    }
  },
  "name": "@grammable/sdk",
  "author": "peanut butter jelly",
  "homepage": "https://github.com/grammable/grammable-sdk",
  "repository": "https://github.com/grammable/grammable-sdk",
  "publishConfig": {
    "access": "public"
  },
  "module": "dist/grammable.esm.js",
  "size-limit": [
    {
      "path": "dist/grammable.cjs.production.min.js",
      "limit": "10 KB"
    },
    {
      "path": "dist/grammable.esm.js",
      "limit": "10 KB"
    }
  ],
}

Run Code Online (Sandbox Code Playgroud)

我删除了 devDependency 和依赖项以删除不必要的行。有人能帮我吗?

这是我的文件夹结构。 文件夹

更新:我尝试过使用npx npm-packlist. 它拥有我需要的一切,但是当我 npm 发布它时,它只构建了 index.js

编辑2:

npm notice   @grammable/sdk@0.1.4
npm notice === Tarball Contents === 
npm notice 35.1kB LICENSE      
npm notice 237B   README.md    
npm notice 184B   dist/index.js
npm notice 1.6kB  package.json 
npm notice === Tarball Details === 
Run Code Online (Sandbox Code Playgroud)

kvo*_*oak 5

tl;dr:.npmignore未指定文件时,npm 将使用您的.gitignore文件设置,其中的dist文件和其中的文件可能会被忽略。

dist/index.js此规则不会忽略您的,因为您mainpackage.json.

npm doc中关于该files字段的特定部分package.json也更清楚地解释了为什么会发生这种行为。

一些特殊的文件和目录也会被包含或排除,无论它们是否存在于文件数组中。

根据这个答案,.npmignore当您指定自己的文件时,问题就可以解决。