简体   繁体   English

npm 仅发布 index.js 并排除其他所有内容

[英]npm publish only publish index.js and excluding everything else

Problems问题

I'm trying to publish my own SDK in npm. When I'm trying to install my packages, my dist folder only shows index.js我正在尝试在 npm 中发布我自己的 SDK。当我尝试安装我的包时,我的 dist 文件夹只显示 index.js

Code:代码:

Here is my package.json file.这是我的package.json文件。 It already includes main and files, https://docs.npmjs.com/cli/v8/using-npm/scripts .它已经包含主要文件和文件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"
    }
  ],
}

I removed my devDependencies and dependencies to remove unnecessary lines.我删除了我的 devDependencies 和依赖项以删除不必要的行。 Can someone help me?有人能帮我吗?

This is my folder structure.这是我的文件夹结构。 folder文件夹

Update: I have tried using npx npm-packlist .更新:我试过使用npx npm-packlist It has everything I need, but when I npm publish it, it only builds index.js它拥有我需要的一切,但是当我 npm 发布它时,它只构建 index.js

Edit 2:编辑 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 === 

tl;dr: When a .npmignore file is not specified, npm will use your .gitignore file setting, where dist and the files in it are likely to get ignored. tl;dr:当未指定.npmignore文件时,npm 将使用您的.gitignore文件设置,其中dist和其中的文件可能会被忽略。

Your dist/index.js isn't ignored by this rule because you specified it in the main field of your package.json .此规则不会忽略您的dist/index.js ,因为您在package.jsonmain字段中指定了它。

And there is this particular part in npm doc about the files field in package.json also explains more clearly why this behavior happens.并且在npm 文档中有这个特定部分关于package.json中的files字段也更清楚地解释了为什么会发生这种行为。

Some special files and directories are also included or excluded regardless of whether they exist in the files array.一些特殊的文件和目录也被包含或排除,不管它们是否存在于文件数组中。

According to this answer the issue can be solved when you specify your own .npmignore file.根据这个答案,当您指定自己的.npmignore文件时,问题就可以解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM