首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >npm仅发布index.js,并排除其他所有内容。

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

Stack Overflow用户
提问于 2022-03-09 09:13:53
回答 1查看 877关注 0票数 1

问题

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

代码:

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

代码语言:javascript
复制
{
  "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"
    }
  ],
}

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

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

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

编辑2:

代码语言:javascript
复制
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 === 
EN

回答 1

Stack Overflow用户

发布于 2022-03-09 09:38:24

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

您的dist/index.js不会被此规则忽略,因为您在package.jsonmain字段中指定了它。

npm博士中有一个关于package.json中的files字段的特殊部分,它也更清楚地解释了为什么会发生这种行为。

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

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71406870

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档