当前位置: 首页 > news >正文

前端 JS 经典:package.json 属性详解

前言:package.json 里的字段大致分两部分,一部分标准字段,一部分非标字段。标准字段就是官方定义好的字段,非标字段包括作者自定义字段

1. 标准字段

1.1 name

包名,就是我们用 npm 去下载的名字,就定义在这。

{"name": "yqcoder-admin-ts"
}

1.2 version

版本,当前包的版本号

{"version": "0.0.0"
}

1.3 description

描述,描述这个包的主要用途

{"description": "this is a system"
}

1.4 main

入口文件,指定这个包的入口文件,如果不设置默认包根目录的 index.js 文件

{"main": "index.js"
}

1.5 files

指定包开发完成后上传到 npm 的文件。

{"files": ["index.js", "dist"]
}

1.6 repository

包上传后的仓库信息

{"repository": {"type": "git","url": "xxxx/xx/xxx.git","directory": "packages/xxx"}
}

1.7 keywords

npm 上的搜索关键字

{"keywords": ["admin"]
}

1.8 author

包作者

{"author": "Yqcoder"
}

1.9 license

提供开源许可类型

{"license": "MIT"
}

1.10 bugs

提交 issues 地址

{"bugs": "https://github.com/xxx/xxx"
}

1.11 homepage

展示一些官网首页

{"homepage": "https://github.com/xxxx"
}

1.12 dependencies

生产环境下需要用到的依赖

{"dependencies": {"@amap/amap-jsapi-loader": "^1.0.1"}
}

1.13 devDependencies

开发阶段时需要的依赖包,不需要在生产中使用

{"devDependencies": {"sass": "^1.70.0"}
}

1.14 scripts

终端脚本语言

{"scripts": {"dev": "vite","build": "vue-tsc && vite build","preview": "vite preview"}
}

2. 非标字段

2.1 module

给构建工具看的,在使用构建工具的情况下,去导入一个包,特别是使用 ESM 模块方法的时候,会把 module 设置的文件给你

{"module": "dist/xxxx.esm-bundler.js"
}

2.2 types

给 ts 看的,整个包的类型定义文件

{"types": "dist/xxx.d.ts"
}

2.3 unpkg

给 cdn 看的,有些用户导入包的时候会使用 CDN,在用这种方式导入的时候,CDN 会从 npm 上去下载相应的文件,从哪里下载?就从这个文件路径下载。

{"unpkg": "dist/xxx.global.js"
}

2.4 jsdelivr

给 cdn 看的

{"jsdelivr": "dist/xxx.global.js"
}

2.5 exports

给构架工具看的,在构建工具的环境中,你在导入包的时候有很多方式。

{"exports": {".": {"types": "./dist/xxxx.d.ts"},"./*": "./*"}
}

2.6 sideEffects

给构建工具看的,标识下包有没有副作用

{"sideEffects": false
}

2.7 buildOptions

作者自定义,提供一些 rollup 的打包信息的。

{"buildOptions": {"name": "xxxx","formats": ["esm-bunder"]}
}

3. vue 中的 package.json 文件

{"name": "vue","version": "2.7.16","packageManager": "pnpm@8.9.2","description": "Reactive, component-oriented view layer for modern web interfaces.","main": "dist/vue.runtime.common.js","module": "dist/vue.runtime.esm.js","unpkg": "dist/vue.js","jsdelivr": "dist/vue.js","typings": "types/index.d.ts","files": ["src","dist/*.js","dist/*.mjs","types/*.d.ts","compiler-sfc","packages/compiler-sfc"],"exports": {".": {"types": "./types/index.d.ts","import": {"node": "./dist/vue.runtime.mjs","default": "./dist/vue.runtime.esm.js"},"require": "./dist/vue.runtime.common.js"},"./compiler-sfc": {"types": "./compiler-sfc/index.d.ts","import": "./compiler-sfc/index.mjs","require": "./compiler-sfc/index.js"},"./dist/*": "./dist/*","./types/*": ["./types/*.d.ts", "./types/*"],"./package.json": "./package.json"},"sideEffects": false,"scripts": {"dev": "rollup -w -c scripts/config.js --environment TARGET:full-dev","dev:cjs": "rollup -w -c scripts/config.js --environment TARGET:runtime-cjs-dev","dev:esm": "rollup -w -c scripts/config.js --environment TARGET:runtime-esm","dev:ssr": "rollup -w -c scripts/config.js --environment TARGET:server-renderer","dev:compiler": "rollup -w -c scripts/config.js --environment TARGET:compiler ","build": "node scripts/build.js","build:ssr": "npm run build -- runtime-cjs,server-renderer","build:types": "rimraf temp && tsc --declaration --emitDeclarationOnly --outDir temp && api-extractor run && api-extractor run -c packages/compiler-sfc/api-extractor.json","test": "npm run ts-check && npm run test:types && npm run test:unit && npm run test:e2e && npm run test:ssr && npm run test:sfc","test:unit": "vitest run test/unit","test:ssr": "npm run build:ssr && vitest run server-renderer","test:sfc": "vitest run compiler-sfc","test:e2e": "npm run build -- full-prod,server-renderer-basic && vitest run test/e2e","test:transition": "karma start test/transition/karma.conf.js","test:types": "npm run build:types && tsc -p ./types/tsconfig.json","format": "prettier --write --parser typescript \"(src|test|packages|types)/**/*.ts\"","ts-check": "tsc -p tsconfig.json --noEmit","ts-check:test": "tsc -p test/tsconfig.json --noEmit","bench:ssr": "npm run build:ssr && node benchmarks/ssr/renderToString.js && node benchmarks/ssr/renderToStream.js","release": "node scripts/release.js","changelog": "conventional-changelog -p angular -i CHANGELOG.md -s"},"gitHooks": {"pre-commit": "lint-staged","commit-msg": "node scripts/verify-commit-msg.js"},"lint-staged": {"*.js": ["prettier --write"],"*.ts": ["prettier --parser=typescript --write"]},"repository": {"type": "git","url": "git+https://github.com/vuejs/vue.git"},"keywords": ["vue"],"author": "Evan You","license": "MIT","bugs": {"url": "https://github.com/vuejs/vue/issues"},"homepage": "https://github.com/vuejs/vue#readme","dependencies": {"@vue/compiler-sfc": "workspace:*","csstype": "^3.1.0"},"devDependencies": {"@babel/parser": "^7.23.5","@microsoft/api-extractor": "^7.25.0","@rollup/plugin-alias": "^3.1.9","@rollup/plugin-commonjs": "^22.0.0","@rollup/plugin-node-resolve": "^13.3.0","@rollup/plugin-replace": "^4.0.0","@types/he": "^1.1.2","@types/node": "^20.10.3","chalk": "^4.1.2","conventional-changelog-cli": "^2.2.2","cross-spawn": "^7.0.3","enquirer": "^2.3.6","esbuild": "^0.19.8","execa": "^4.1.0","he": "^1.2.0","jasmine-core": "^4.2.0","jsdom": "^19.0.0","karma": "^6.3.20","karma-chrome-launcher": "^3.1.1","karma-cli": "^2.0.0","karma-esbuild": "^2.2.5","karma-jasmine": "^5.0.1","lint-staged": "^12.5.0","lodash": "^4.17.21","marked": "^4.0.16","minimist": "^1.2.6","postcss": "^8.4.14","prettier": "^2.6.2","puppeteer": "^14.3.0","rimraf": "^3.0.2","rollup": "^2.79.1","rollup-plugin-typescript2": "^0.32.0","semver": "^7.3.7","shelljs": "^0.8.5","terser": "^5.14.0","todomvc-app-css": "^2.4.2","ts-node": "^10.8.1","tslib": "^2.4.0","typescript": "^4.8.4","vitest": "^1.0.4","yorkie": "^2.0.0"}
}

相关文章:

  • 安装前端依赖node-sass报错
  • 【LLM之RAG】Adaptive-RAG论文阅读笔记
  • C语言 | Leetcode C语言题解之第151题反转字符串中的单词
  • 学习java第一百天
  • 「前端+鸿蒙」鸿蒙应用开发-ArkTS语法说明-自定义组件
  • 深入浅出MyBatis:全面解析与实战指南
  • 蓝牙耳机怎么连接电脑?轻松实现无线连接
  • 10.错误处理
  • 开源大模型的新星:ChatGPT-Next-Web 项目解析与推荐
  • 百度网盘限速解决办法
  • 构建LangChain应用程序的示例代码:33、如何在LangChain框架中使用HumanInputChatModel来模拟人工输入的聊天模型教程
  • 二分查找总结:算法原理,适用题型,经典题单
  • 禁用PS/Photoshop等一系列Adobe旗下软件联网外传用户数据操作
  • java是值传递还是引用传递?
  • 【C++课程学习】:类和对象(拷贝构造和运算符重载)
  • 【347天】每日项目总结系列085(2018.01.18)
  • android高仿小视频、应用锁、3种存储库、QQ小红点动画、仿支付宝图表等源码...
  • C++回声服务器_9-epoll边缘触发模式版本服务器
  • C++类中的特殊成员函数
  • chrome扩展demo1-小时钟
  • Docker 笔记(2):Dockerfile
  • Java 9 被无情抛弃,Java 8 直接升级到 Java 10!!
  • js中forEach回调同异步问题
  • leetcode讲解--894. All Possible Full Binary Trees
  • MYSQL 的 IF 函数
  • Quartz初级教程
  • SpiderData 2019年2月16日 DApp数据排行榜
  • 极限编程 (Extreme Programming) - 发布计划 (Release Planning)
  • 免费小说阅读小程序
  • 数据结构java版之冒泡排序及优化
  • 云大使推广中的常见热门问题
  • Redis4.x新特性 -- 萌萌的MEMORY DOCTOR
  • ###51单片机学习(2)-----如何通过C语言运用延时函数设计LED流水灯
  • #单片机(TB6600驱动42步进电机)
  • $(this) 和 this 关键字在 jQuery 中有何不同?
  • (delphi11最新学习资料) Object Pascal 学习笔记---第8章第2节(共同的基类)
  • (env: Windows,mp,1.06.2308310; lib: 3.2.4) uniapp微信小程序
  • (Matlab)基于蝙蝠算法实现电力系统经济调度
  • (第一天)包装对象、作用域、创建对象
  • (二)基于wpr_simulation 的Ros机器人运动控制,gazebo仿真
  • (分类)KNN算法- 参数调优
  • (附源码)spring boot基于Java的电影院售票与管理系统毕业设计 011449
  • (附源码)springboot青少年公共卫生教育平台 毕业设计 643214
  • (十七)devops持续集成开发——使用jenkins流水线pipeline方式发布一个微服务项目
  • (转)Google的Objective-C编码规范
  • .locked1、locked勒索病毒解密方法|勒索病毒解决|勒索病毒恢复|数据库修复
  • .NET : 在VS2008中计算代码度量值
  • .net 使用$.ajax实现从前台调用后台方法(包含静态方法和非静态方法调用)
  • .NET 通过系统影子账户实现权限维持
  • .NET/C# 中你可以在代码中写多个 Main 函数,然后按需要随时切换
  • .Net开发笔记(二十)创建一个需要授权的第三方组件
  • .NET中统一的存储过程调用方法(收藏)
  • /deep/和 >>>以及 ::v-deep 三者的区别
  • ::什么意思
  • @Builder用法