记录一下npm包的关键字段

  • module: 字段指定了 ES 模块版本的入口文件路径,
  • main: 字段则指定了 CommonJS 模块版本的入口文件路径。

注意:尽管 module 字段在构建工具中被广泛支持,但它并不是所有 JavaScript 环境都遵循的规范。在 Node.js 中,通常使用 main 字段指定 CommonJS 模块的入口,而在现代浏览器环境中,使用 type=“module” 的 script 标签加载模块时会优先考虑 module 字段。

  • exports 字段:
    • 作用: exports 字段是 Node.js 12+ 版本引入的,它用于指定模块的导出规则,允许你定义模块的多个入口。
    • 用法: exports 字段可以用来指定模块的入口文件,允许你为不同的环境提供不同的入口。它支持多种格式,例如:
    • 注意: 目前 exports 字段在 Node.js 环境中得到较好的支持,但在其他环境中的兼容性可能有限。
{
   
  "name": "hex-event-track",
  "version": "1.0.4",
  "description": "",
  "type": "module",
  "scripts": {
   
    "build": "tsup --global-name globalHexEventTrack",
    "watch": "tsup --watch --global-name globalHexEventTrack",
    "test": "vitest -u"
  },
  "keywords": [
    "hexfuture event track"
  ],
  "author": "",
  "license": "ISC",
  "devDependencies": {
   
    "@types/ua-parser-js": "^0.7.37",
    "eslint": "^8.46.0",
    "tsup": "^7.2.0",
    "typescript": "^5.1.6",
    "vitest": "^0.34.4"
  },
  "files": [
    "dist",
    "src"
  ],
  "types": "./dist/index.d",
  "main": "./dist/index.js",
  "exports": {
   
    ".": {
   
      "import": "./dist/index.js",
      "require": "./dist/index.cjs"
    }
  },
  "repository": {
   
    "type": "git"
  },
  "dependencies": {
   
    "ua-parser-js": "^1.0.36"
  }
}

遇到的问题

我在使用老版本vuecli时遇到了不识别exports字段的问题。需要加上 main 字段

相关推荐

  1. 记录一下npm关键字

    2023-12-07 18:08:01       43 阅读
  2. 发布自己npm

    2023-12-07 18:08:01       14 阅读
  3. npm】如何发布自己npm

    2023-12-07 18:08:01       35 阅读
  4. 从0制作一个npm

    2023-12-07 18:08:01       14 阅读

最近更新

  1. TCP协议是安全的吗?

    2023-12-07 18:08:01       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2023-12-07 18:08:01       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2023-12-07 18:08:01       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2023-12-07 18:08:01       20 阅读

热门阅读

  1. TCP套接字编写

    2023-12-07 18:08:01       36 阅读
  2. pm2部署vue项目,Vue项目的部署在服务器

    2023-12-07 18:08:01       33 阅读
  3. StarRocks 存算分离最佳实践,让降本增效更简单

    2023-12-07 18:08:01       40 阅读
  4. STM32h7 接收各种can id情况下滤波器的配置

    2023-12-07 18:08:01       33 阅读
  5. 解决SpringBoot jar包下resources目录下文件读取不到

    2023-12-07 18:08:01       41 阅读
  6. Conda常用指令---(频率很高)

    2023-12-07 18:08:01       41 阅读
  7. 无图谱不AI之三元组数据保存Neo4j

    2023-12-07 18:08:01       29 阅读
  8. git-5

    git-5

    2023-12-07 18:08:01      31 阅读
  9. 【Appium】解决搜索输入框无搜索按钮

    2023-12-07 18:08:01       34 阅读
  10. Node.js 的 https 模块介绍

    2023-12-07 18:08:01       27 阅读