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

news/2024/6/18 21:22:50 标签: 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"
  }
}

http://www.niftyadmin.cn/n/5520392.html

相关文章

selenium使用已经打开的浏览器

Selenium 本身不支持直接连接到一个已经打开的浏览器页面。Selenium 启动的浏览器实例是一个全新的会话,它与手动打开的浏览器页面是分开的。但是,有一些变通的方法可以实现类似的效果。 一种方法是通过附加代理连接到已经打开的浏览器。下面是如何实现…

数智教育创新如何向未来?腾讯云与你探索革新之路

引言 随着科技革命的快速发展,掀起教育领域的变革,新理念、新技术、新模式、新应用正不断涌现,正塑造着教育的未来形态。未来科技还将如何赋能教育创新? 5月31日,由腾讯云TVP 与西安电子科技大学联合举办的「数智教育的…

Kotlin 语言基础学习

什么是Kotlin ? Kotiln翻译为中文是:靠他灵。它是由JetBrains 这家公司开发的,JetBrains 是一家编译器软件起家的,例如常用的WebStorm、IntelliJ IDEA等软件。 Kotlin官网 JetBrains 官网 Kotlin 语言目前的现状: 目前Android 已将Kotlin 作为官方开发语言。 Spring 框…

使用thymeleaf直接渲染字符串

目录 一、依赖 二、示例代码 一、依赖 <--JAVA 8--><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-thymeleaf</artifactId><version>2.7.18</version></dependency><-…

grub引导LinuxMint

注意事项&#xff1a;文件系统必须是FAT32 安装 sudo apt install gparted -y 分区管理软件 使用gparted分区和查看设备路径 sudo apt-get install grub-efi-amd64 #/dev/sdd1 是需要制作分区引导的设备路径 sudo mount /dev/sdd1 /mnt/123 #bios sudo grub-install --targe…

TLE9879的基于Arduino调试板SWD刷写接口

官方的Arduino评估板&#xff0c;如下图所示&#xff1a; 如果你有官方的调试器&#xff0c;应该不用关注本文章&#xff0c;如下图连接就是&#xff1a; 如果&#xff0c;您和博主一样需要自己飞线的话&#xff0c;如下图所示&#xff1a;PCB的名称在右边整理&#xff0c;SWD的…

Prompt-to-Prompt Image Editing with Cross Attention Control

Prompt-to-Prompt Image Editing with Cross Attention Control (P2P) Amir Hertz, Tel Aviv University, ICLR23, Paper, Code 1. 前言 编辑对这些生成模型来说是具有挑战性的&#xff0c;因为编辑技术的一个固有特性是保留大部分原始图像&#xff0c;而在基于文本的模型中…

upload-labs第九关教程

upload-labs第九关教程 一、源代码分析代码审计::$DATA介绍 二、绕过分析特殊字符::$data绕过上传eval.php使用burpsuite抓包进行修改放包&#xff0c;查看是否上传成功使用中国蚁剑进行连接 一、源代码分析 代码审计 $is_upload false; $msg null; if (isset($_POST[submi…