123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width,initial-scale=1">
- <title>npm packageJson属性详解 | 彪哥博客</title>
- <meta name="generator" content="VuePress 1.9.5">
- <link rel="icon" href="/blog/img/favicon.ico">
- <meta name="description" content="web前端技术博客,专注web前端学习与总结。JavaScript,js,ES6,TypeScript,vue,React,python,css3,html5,Node,git,github等技术文章。">
- <meta name="keywords" content="前端博客,个人技术博客,前端,前端开发,前端框架,web前端,前端面试题,技术文档,学习,面试,JavaScript,js,ES6,TypeScript,vue,python,css3,html5,Node,git,github,markdown">
- <meta name="theme-color" content="#11a8cd">
-
- <link rel="preload" href="/blog/assets/css/0.styles.dc03b589.css" as="style"><link rel="preload" href="/blog/assets/js/app.90754bd5.js" as="script"><link rel="preload" href="/blog/assets/js/2.106f41fb.js" as="script"><link rel="preload" href="/blog/assets/js/3.6748bd5c.js" as="script"><link rel="preload" href="/blog/assets/js/54.dbb7c9ab.js" as="script"><link rel="prefetch" href="/blog/assets/js/10.cad3aa70.js"><link rel="prefetch" href="/blog/assets/js/100.08a8b2d8.js"><link rel="prefetch" href="/blog/assets/js/101.2aabb12c.js"><link rel="prefetch" href="/blog/assets/js/102.13f3cc4d.js"><link rel="prefetch" href="/blog/assets/js/103.c19aee03.js"><link rel="prefetch" href="/blog/assets/js/104.91a6aec1.js"><link rel="prefetch" href="/blog/assets/js/105.71de1aa4.js"><link rel="prefetch" href="/blog/assets/js/106.207422de.js"><link rel="prefetch" href="/blog/assets/js/107.bf754f60.js"><link rel="prefetch" href="/blog/assets/js/108.87ddbf21.js"><link rel="prefetch" href="/blog/assets/js/109.de6075c6.js"><link rel="prefetch" href="/blog/assets/js/11.f2e9eca8.js"><link rel="prefetch" href="/blog/assets/js/110.f19c57ae.js"><link rel="prefetch" href="/blog/assets/js/111.da99a105.js"><link rel="prefetch" href="/blog/assets/js/112.9dd75c6f.js"><link rel="prefetch" href="/blog/assets/js/113.9322f157.js"><link rel="prefetch" href="/blog/assets/js/114.c5150cc6.js"><link rel="prefetch" href="/blog/assets/js/115.4fb547bf.js"><link rel="prefetch" href="/blog/assets/js/116.2ddf1aa8.js"><link rel="prefetch" href="/blog/assets/js/117.3c970f48.js"><link rel="prefetch" href="/blog/assets/js/118.921e1d54.js"><link rel="prefetch" href="/blog/assets/js/119.0141defb.js"><link rel="prefetch" href="/blog/assets/js/12.98512c60.js"><link rel="prefetch" href="/blog/assets/js/120.de47a761.js"><link rel="prefetch" href="/blog/assets/js/121.a0b3693a.js"><link rel="prefetch" href="/blog/assets/js/122.6c7dd225.js"><link rel="prefetch" href="/blog/assets/js/123.dbff103c.js"><link rel="prefetch" href="/blog/assets/js/124.493776ef.js"><link rel="prefetch" href="/blog/assets/js/125.554c9fbf.js"><link rel="prefetch" href="/blog/assets/js/126.2421fe84.js"><link rel="prefetch" href="/blog/assets/js/127.805f10a4.js"><link rel="prefetch" href="/blog/assets/js/128.6543adba.js"><link rel="prefetch" href="/blog/assets/js/129.d7c56b92.js"><link rel="prefetch" href="/blog/assets/js/13.a79fa0c7.js"><link rel="prefetch" href="/blog/assets/js/130.593d21f0.js"><link rel="prefetch" href="/blog/assets/js/131.4c90d8b8.js"><link rel="prefetch" href="/blog/assets/js/132.4ad12bdc.js"><link rel="prefetch" href="/blog/assets/js/133.485de1b9.js"><link rel="prefetch" href="/blog/assets/js/134.78bc8f57.js"><link rel="prefetch" href="/blog/assets/js/135.47498729.js"><link rel="prefetch" href="/blog/assets/js/136.d99350df.js"><link rel="prefetch" href="/blog/assets/js/137.57ba6d3f.js"><link rel="prefetch" href="/blog/assets/js/138.d976c801.js"><link rel="prefetch" href="/blog/assets/js/139.766f20b7.js"><link rel="prefetch" href="/blog/assets/js/14.0fdf0c78.js"><link rel="prefetch" href="/blog/assets/js/140.0d9b8fbc.js"><link rel="prefetch" href="/blog/assets/js/141.128b6e26.js"><link rel="prefetch" href="/blog/assets/js/142.e004a584.js"><link rel="prefetch" href="/blog/assets/js/143.5a19a0b2.js"><link rel="prefetch" href="/blog/assets/js/144.5f397211.js"><link rel="prefetch" href="/blog/assets/js/145.cde5f3a0.js"><link rel="prefetch" href="/blog/assets/js/146.4185092c.js"><link rel="prefetch" href="/blog/assets/js/147.ac0e55d3.js"><link rel="prefetch" href="/blog/assets/js/148.30f02604.js"><link rel="prefetch" href="/blog/assets/js/149.760a79ed.js"><link rel="prefetch" href="/blog/assets/js/15.fce722b2.js"><link rel="prefetch" href="/blog/assets/js/150.3a1675b7.js"><link rel="prefetch" href="/blog/assets/js/151.0d73a46e.js"><link rel="prefetch" href="/blog/assets/js/152.c9c054d4.js"><link rel="prefetch" href="/blog/assets/js/153.b007c8a2.js"><link rel="prefetch" href="/blog/assets/js/154.a3acc6bf.js"><link rel="prefetch" href="/blog/assets/js/155.b5c0abcd.js"><link rel="prefetch" href="/blog/assets/js/156.2ba750fc.js"><link rel="prefetch" href="/blog/assets/js/157.fe92af0c.js"><link rel="prefetch" href="/blog/assets/js/158.e16fda40.js"><link rel="prefetch" href="/blog/assets/js/159.7fc7fd44.js"><link rel="prefetch" href="/blog/assets/js/16.871928af.js"><link rel="prefetch" href="/blog/assets/js/160.b581a0f4.js"><link rel="prefetch" href="/blog/assets/js/161.97acae68.js"><link rel="prefetch" href="/blog/assets/js/162.cec1b9a3.js"><link rel="prefetch" href="/blog/assets/js/163.a00f98f7.js"><link rel="prefetch" href="/blog/assets/js/164.cbf4cf52.js"><link rel="prefetch" href="/blog/assets/js/165.bc7a523a.js"><link rel="prefetch" href="/blog/assets/js/166.ca626fb4.js"><link rel="prefetch" href="/blog/assets/js/167.0ca68106.js"><link rel="prefetch" href="/blog/assets/js/168.2e605db8.js"><link rel="prefetch" href="/blog/assets/js/169.401b96d4.js"><link rel="prefetch" href="/blog/assets/js/17.2399cb2b.js"><link rel="prefetch" href="/blog/assets/js/170.7c8b0366.js"><link rel="prefetch" href="/blog/assets/js/171.c3155533.js"><link rel="prefetch" href="/blog/assets/js/172.b659d767.js"><link rel="prefetch" href="/blog/assets/js/173.62c681db.js"><link rel="prefetch" href="/blog/assets/js/174.5c66f092.js"><link rel="prefetch" href="/blog/assets/js/175.d41dd28b.js"><link rel="prefetch" href="/blog/assets/js/176.e60d7f0a.js"><link rel="prefetch" href="/blog/assets/js/177.10de95b1.js"><link rel="prefetch" href="/blog/assets/js/178.f301674d.js"><link rel="prefetch" href="/blog/assets/js/179.77bb52e9.js"><link rel="prefetch" href="/blog/assets/js/18.c338fe95.js"><link rel="prefetch" href="/blog/assets/js/180.d2a4e612.js"><link rel="prefetch" href="/blog/assets/js/181.a53e32e0.js"><link rel="prefetch" href="/blog/assets/js/182.38687994.js"><link rel="prefetch" href="/blog/assets/js/183.544fef00.js"><link rel="prefetch" href="/blog/assets/js/184.711e54a6.js"><link rel="prefetch" href="/blog/assets/js/185.20075148.js"><link rel="prefetch" href="/blog/assets/js/186.08c67f20.js"><link rel="prefetch" href="/blog/assets/js/187.7ca2d0c6.js"><link rel="prefetch" href="/blog/assets/js/188.cd167879.js"><link rel="prefetch" href="/blog/assets/js/189.e8e2eb21.js"><link rel="prefetch" href="/blog/assets/js/19.6b963460.js"><link rel="prefetch" href="/blog/assets/js/190.8b557318.js"><link rel="prefetch" href="/blog/assets/js/191.10d0f80b.js"><link rel="prefetch" href="/blog/assets/js/192.127fef4c.js"><link rel="prefetch" href="/blog/assets/js/193.781690eb.js"><link rel="prefetch" href="/blog/assets/js/194.4b375e2e.js"><link rel="prefetch" href="/blog/assets/js/195.003e3d67.js"><link rel="prefetch" href="/blog/assets/js/196.7a3f55e5.js"><link rel="prefetch" href="/blog/assets/js/197.30d4c5b4.js"><link rel="prefetch" href="/blog/assets/js/198.628c2c1a.js"><link rel="prefetch" href="/blog/assets/js/199.d7c8cbb8.js"><link rel="prefetch" href="/blog/assets/js/20.839dae41.js"><link rel="prefetch" href="/blog/assets/js/200.1fed86d2.js"><link rel="prefetch" href="/blog/assets/js/201.5ba078d9.js"><link rel="prefetch" href="/blog/assets/js/202.b49b23f4.js"><link rel="prefetch" href="/blog/assets/js/203.d88a03d9.js"><link rel="prefetch" href="/blog/assets/js/204.fb928277.js"><link rel="prefetch" href="/blog/assets/js/205.432c3d8d.js"><link rel="prefetch" href="/blog/assets/js/206.ed726599.js"><link rel="prefetch" href="/blog/assets/js/207.c3794556.js"><link rel="prefetch" href="/blog/assets/js/208.416f7a9e.js"><link rel="prefetch" href="/blog/assets/js/209.d396aad5.js"><link rel="prefetch" href="/blog/assets/js/21.bd21bd29.js"><link rel="prefetch" href="/blog/assets/js/210.02e4ee2f.js"><link rel="prefetch" href="/blog/assets/js/211.0f8a9304.js"><link rel="prefetch" href="/blog/assets/js/212.9220dd3d.js"><link rel="prefetch" href="/blog/assets/js/213.89521ebd.js"><link rel="prefetch" href="/blog/assets/js/214.cd5ec468.js"><link rel="prefetch" href="/blog/assets/js/215.0084d772.js"><link rel="prefetch" href="/blog/assets/js/216.ebd468b9.js"><link rel="prefetch" href="/blog/assets/js/217.fac21407.js"><link rel="prefetch" href="/blog/assets/js/218.9793e19a.js"><link rel="prefetch" href="/blog/assets/js/219.b99343b6.js"><link rel="prefetch" href="/blog/assets/js/22.e6bcf65d.js"><link rel="prefetch" href="/blog/assets/js/220.8065033b.js"><link rel="prefetch" href="/blog/assets/js/221.97268a80.js"><link rel="prefetch" href="/blog/assets/js/222.22bf261f.js"><link rel="prefetch" href="/blog/assets/js/223.d5ff1bff.js"><link rel="prefetch" href="/blog/assets/js/224.364b4b11.js"><link rel="prefetch" href="/blog/assets/js/225.bd8b00c7.js"><link rel="prefetch" href="/blog/assets/js/226.78192713.js"><link rel="prefetch" href="/blog/assets/js/227.06ec006e.js"><link rel="prefetch" href="/blog/assets/js/228.166546a8.js"><link rel="prefetch" href="/blog/assets/js/229.fd44d2be.js"><link rel="prefetch" href="/blog/assets/js/23.ebbc3fd3.js"><link rel="prefetch" href="/blog/assets/js/230.109a1752.js"><link rel="prefetch" href="/blog/assets/js/231.c6faedb6.js"><link rel="prefetch" href="/blog/assets/js/232.f938a3a8.js"><link rel="prefetch" href="/blog/assets/js/233.0dc59324.js"><link rel="prefetch" href="/blog/assets/js/234.bb73adca.js"><link rel="prefetch" href="/blog/assets/js/235.97ed69db.js"><link rel="prefetch" href="/blog/assets/js/236.a8c51930.js"><link rel="prefetch" href="/blog/assets/js/237.6ae31c88.js"><link rel="prefetch" href="/blog/assets/js/238.2f5c56ae.js"><link rel="prefetch" href="/blog/assets/js/239.506a4e9f.js"><link rel="prefetch" href="/blog/assets/js/24.19bd04ec.js"><link rel="prefetch" href="/blog/assets/js/25.b4de33d1.js"><link rel="prefetch" href="/blog/assets/js/26.0bb98ba9.js"><link rel="prefetch" href="/blog/assets/js/27.df98327e.js"><link rel="prefetch" href="/blog/assets/js/28.31289bac.js"><link rel="prefetch" href="/blog/assets/js/29.45af5621.js"><link rel="prefetch" href="/blog/assets/js/30.d5c08e66.js"><link rel="prefetch" href="/blog/assets/js/31.78e43a68.js"><link rel="prefetch" href="/blog/assets/js/32.53ca76ee.js"><link rel="prefetch" href="/blog/assets/js/33.081e8ef6.js"><link rel="prefetch" href="/blog/assets/js/34.cb1866c1.js"><link rel="prefetch" href="/blog/assets/js/35.314ba98e.js"><link rel="prefetch" href="/blog/assets/js/36.1f6a5fae.js"><link rel="prefetch" href="/blog/assets/js/37.45e6d22f.js"><link rel="prefetch" href="/blog/assets/js/38.70b82353.js"><link rel="prefetch" href="/blog/assets/js/39.df6c26ac.js"><link rel="prefetch" href="/blog/assets/js/4.44654b1a.js"><link rel="prefetch" href="/blog/assets/js/40.80101c19.js"><link rel="prefetch" href="/blog/assets/js/41.2b5e8c27.js"><link rel="prefetch" href="/blog/assets/js/42.c6ded3fe.js"><link rel="prefetch" href="/blog/assets/js/43.6d9424d6.js"><link rel="prefetch" href="/blog/assets/js/44.835e4b5c.js"><link rel="prefetch" href="/blog/assets/js/45.d74d29a2.js"><link rel="prefetch" href="/blog/assets/js/46.d15a7dc0.js"><link rel="prefetch" href="/blog/assets/js/47.8d66ca97.js"><link rel="prefetch" href="/blog/assets/js/48.3c1102e1.js"><link rel="prefetch" href="/blog/assets/js/49.e17a3436.js"><link rel="prefetch" href="/blog/assets/js/5.88de390f.js"><link rel="prefetch" href="/blog/assets/js/50.6750f186.js"><link rel="prefetch" href="/blog/assets/js/51.9f93af9f.js"><link rel="prefetch" href="/blog/assets/js/52.f3ef3b5e.js"><link rel="prefetch" href="/blog/assets/js/53.a6bacd25.js"><link rel="prefetch" href="/blog/assets/js/55.2562d0c8.js"><link rel="prefetch" href="/blog/assets/js/56.14ea4931.js"><link rel="prefetch" href="/blog/assets/js/57.a2fad780.js"><link rel="prefetch" href="/blog/assets/js/58.8165b971.js"><link rel="prefetch" href="/blog/assets/js/59.556cab0d.js"><link rel="prefetch" href="/blog/assets/js/6.277038ca.js"><link rel="prefetch" href="/blog/assets/js/60.f048aa7c.js"><link rel="prefetch" href="/blog/assets/js/61.bdb307a8.js"><link rel="prefetch" href="/blog/assets/js/62.37a94f10.js"><link rel="prefetch" href="/blog/assets/js/63.74811780.js"><link rel="prefetch" href="/blog/assets/js/64.81f21b8a.js"><link rel="prefetch" href="/blog/assets/js/65.d970ff03.js"><link rel="prefetch" href="/blog/assets/js/66.cb805d9b.js"><link rel="prefetch" href="/blog/assets/js/67.39f85baa.js"><link rel="prefetch" href="/blog/assets/js/68.7f79766a.js"><link rel="prefetch" href="/blog/assets/js/69.fa8624bd.js"><link rel="prefetch" href="/blog/assets/js/7.e0a6d1b0.js"><link rel="prefetch" href="/blog/assets/js/70.1f3e978d.js"><link rel="prefetch" href="/blog/assets/js/71.13cd9358.js"><link rel="prefetch" href="/blog/assets/js/72.739b22a8.js"><link rel="prefetch" href="/blog/assets/js/73.95f69ae2.js"><link rel="prefetch" href="/blog/assets/js/74.b6624f6a.js"><link rel="prefetch" href="/blog/assets/js/75.b0d9aa06.js"><link rel="prefetch" href="/blog/assets/js/76.681b78df.js"><link rel="prefetch" href="/blog/assets/js/77.46f6e413.js"><link rel="prefetch" href="/blog/assets/js/78.aebd00ee.js"><link rel="prefetch" href="/blog/assets/js/79.1b784d15.js"><link rel="prefetch" href="/blog/assets/js/8.9428e7ee.js"><link rel="prefetch" href="/blog/assets/js/80.1f550d53.js"><link rel="prefetch" href="/blog/assets/js/81.101cc131.js"><link rel="prefetch" href="/blog/assets/js/82.077c8298.js"><link rel="prefetch" href="/blog/assets/js/83.2e375d11.js"><link rel="prefetch" href="/blog/assets/js/84.38102a34.js"><link rel="prefetch" href="/blog/assets/js/85.24532d6a.js"><link rel="prefetch" href="/blog/assets/js/86.1dabbf00.js"><link rel="prefetch" href="/blog/assets/js/87.763da0f2.js"><link rel="prefetch" href="/blog/assets/js/88.ff6e5f7c.js"><link rel="prefetch" href="/blog/assets/js/89.187e5e16.js"><link rel="prefetch" href="/blog/assets/js/9.da143545.js"><link rel="prefetch" href="/blog/assets/js/90.3c8cff94.js"><link rel="prefetch" href="/blog/assets/js/91.a50bd44d.js"><link rel="prefetch" href="/blog/assets/js/92.5484868f.js"><link rel="prefetch" href="/blog/assets/js/93.c8ee75e3.js"><link rel="prefetch" href="/blog/assets/js/94.b18a3e9b.js"><link rel="prefetch" href="/blog/assets/js/95.cddef6ae.js"><link rel="prefetch" href="/blog/assets/js/96.80e5a938.js"><link rel="prefetch" href="/blog/assets/js/97.1f5e5197.js"><link rel="prefetch" href="/blog/assets/js/98.e3a275c8.js"><link rel="prefetch" href="/blog/assets/js/99.d33bf89e.js">
- <link rel="stylesheet" href="/blog/assets/css/0.styles.dc03b589.css">
- </head>
- <body class="theme-mode-light">
- <div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/blog/" class="home-link router-link-active"><img src="/blog/img/logo.png" alt="彪哥博客" class="logo"> <span class="site-name can-hide">彪哥博客</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/blog/" class="nav-link">首页</a></div><div class="nav-item"><a href="http://fseller.com" target="_blank" rel="noopener noreferrer" class="nav-link external">
- 个人游戏网站
- <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="前端" class="dropdown-title"><a href="/blog/web/" class="link-title">前端</a> <span class="title" style="display:none;">前端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>前端文章</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/blog/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>学习笔记</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/blog/note/javascript/" class="nav-link">《JavaScript教程》</a></li><li class="dropdown-subitem"><a href="/blog/note/js/" class="nav-link">《JavaScript高级程序设计》</a></li><li class="dropdown-subitem"><a href="/blog/note/es6/" class="nav-link">《ES6 教程》</a></li><li class="dropdown-subitem"><a href="/blog/note/vue/" class="nav-link">《Vue》</a></li><li class="dropdown-subitem"><a href="/blog/note/react/" class="nav-link">《React》</a></li><li class="dropdown-subitem"><a href="/blog/note/typescript-axios/" class="nav-link">《TypeScript 从零实现 axios》</a></li><li class="dropdown-subitem"><a href="/blog/note/git/" class="nav-link">《Git》</a></li><li class="dropdown-subitem"><a href="/blog/pages/51afd6/" class="nav-link">TypeScript</a></li><li class="dropdown-subitem"><a href="/blog/pages/4643cd/" class="nav-link">JS设计模式总结</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="页面" class="dropdown-title"><a href="/blog/ui/" class="link-title">页面</a> <span class="title" style="display:none;">页面</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/pages/8309a5b876fc95e3/" class="nav-link">HTML</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/0a83b083bdf257cb/" class="nav-link">CSS</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="技术" class="dropdown-title"><a href="/blog/technology/" class="link-title">技术</a> <span class="title" style="display:none;">技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/pages/9a7ee40fc232253e/" class="nav-link">技术文档</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/4c778760be26d8b3/" class="nav-link">GitHub技巧</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/117708e0af7f0bd9/" class="nav-link">Nodejs</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/41f87d890d0a02af/" class="nav-link">博客搭建</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="更多" class="dropdown-title"><a href="/blog/more/" class="link-title">更多</a> <span class="title" style="display:none;">更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/pages/f2a556/" class="nav-link">学习</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/aea6571b7a8bae86/" class="nav-link">面试</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/2d615df9a36a98ed/" class="nav-link">心情杂货</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/baaa02/" class="nav-link">实用技巧</a></li><li class="dropdown-item"><!----> <a href="/blog/friends/" class="nav-link">友情链接</a></li></ul></div></div><div class="nav-item"><a href="/blog/about/" class="nav-link">关于</a></div><div class="nav-item"><a href="/blog/pages/beb6c0bd8a66cea6/" class="nav-link">收藏</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/blog/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/blog/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/blog/archives/" class="nav-link">归档</a></li></ul></div></div> <a href="https://github.com/heBody/blog" target="_blank" rel="noopener noreferrer" class="repo-link">
- GitHub
- <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><div class="blogger"><img src="/blog/img/head.jpg"> <div class="blogger-info"><h3>彪哥</h3> <span>爱好前端</span></div></div> <nav class="nav-links"><div class="nav-item"><a href="/blog/" class="nav-link">首页</a></div><div class="nav-item"><a href="http://fseller.com" target="_blank" rel="noopener noreferrer" class="nav-link external">
- 个人游戏网站
- <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="前端" class="dropdown-title"><a href="/blog/web/" class="link-title">前端</a> <span class="title" style="display:none;">前端</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>前端文章</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/blog/pages/8143cc480faf9a11/" class="nav-link">JavaScript</a></li></ul></li><li class="dropdown-item"><h4>学习笔记</h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/blog/note/javascript/" class="nav-link">《JavaScript教程》</a></li><li class="dropdown-subitem"><a href="/blog/note/js/" class="nav-link">《JavaScript高级程序设计》</a></li><li class="dropdown-subitem"><a href="/blog/note/es6/" class="nav-link">《ES6 教程》</a></li><li class="dropdown-subitem"><a href="/blog/note/vue/" class="nav-link">《Vue》</a></li><li class="dropdown-subitem"><a href="/blog/note/react/" class="nav-link">《React》</a></li><li class="dropdown-subitem"><a href="/blog/note/typescript-axios/" class="nav-link">《TypeScript 从零实现 axios》</a></li><li class="dropdown-subitem"><a href="/blog/note/git/" class="nav-link">《Git》</a></li><li class="dropdown-subitem"><a href="/blog/pages/51afd6/" class="nav-link">TypeScript</a></li><li class="dropdown-subitem"><a href="/blog/pages/4643cd/" class="nav-link">JS设计模式总结</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="页面" class="dropdown-title"><a href="/blog/ui/" class="link-title">页面</a> <span class="title" style="display:none;">页面</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/pages/8309a5b876fc95e3/" class="nav-link">HTML</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/0a83b083bdf257cb/" class="nav-link">CSS</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="技术" class="dropdown-title"><a href="/blog/technology/" class="link-title">技术</a> <span class="title" style="display:none;">技术</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/pages/9a7ee40fc232253e/" class="nav-link">技术文档</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/4c778760be26d8b3/" class="nav-link">GitHub技巧</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/117708e0af7f0bd9/" class="nav-link">Nodejs</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/41f87d890d0a02af/" class="nav-link">博客搭建</a></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="更多" class="dropdown-title"><a href="/blog/more/" class="link-title">更多</a> <span class="title" style="display:none;">更多</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/pages/f2a556/" class="nav-link">学习</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/aea6571b7a8bae86/" class="nav-link">面试</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/2d615df9a36a98ed/" class="nav-link">心情杂货</a></li><li class="dropdown-item"><!----> <a href="/blog/pages/baaa02/" class="nav-link">实用技巧</a></li><li class="dropdown-item"><!----> <a href="/blog/friends/" class="nav-link">友情链接</a></li></ul></div></div><div class="nav-item"><a href="/blog/about/" class="nav-link">关于</a></div><div class="nav-item"><a href="/blog/pages/beb6c0bd8a66cea6/" class="nav-link">收藏</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="索引" class="dropdown-title"><a href="/blog/archives/" class="link-title">索引</a> <span class="title" style="display:none;">索引</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/blog/categories/" class="nav-link">分类</a></li><li class="dropdown-item"><!----> <a href="/blog/tags/" class="nav-link">标签</a></li><li class="dropdown-item"><!----> <a href="/blog/archives/" class="nav-link">归档</a></li></ul></div></div> <a href="https://github.com/heBody/blog" target="_blank" rel="noopener noreferrer" class="repo-link">
- GitHub
- <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav> <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>技术文档</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/blog/pages/9a7ee40fc232253e/" class="sidebar-link">Git使用手册</a></li><li><a href="/blog/pages/ad247c4332211551/" class="sidebar-link">Markdown使用教程</a></li><li><a href="/blog/pages/61f2f95fd7da14fd/" class="sidebar-link">npm常用命令</a></li><li><a href="/blog/pages/dec4f3f00e71a312/" aria-current="page" class="active sidebar-link">npm packageJson属性详解</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#概述" class="sidebar-link">概述</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#name" class="sidebar-link">name</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#version" class="sidebar-link">version</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#description" class="sidebar-link">description</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#keywords" class="sidebar-link">keywords</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#homepage" class="sidebar-link">homepage</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#bugs" class="sidebar-link">bugs</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#license" class="sidebar-link">license</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#和用户相关的属性-author-contributors" class="sidebar-link">和用户相关的属性: author, contributors</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#files" class="sidebar-link">files</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#main" class="sidebar-link">main</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#bin" class="sidebar-link">bin</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#man" class="sidebar-link">man</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#directories" class="sidebar-link">directories</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level3"><a href="/blog/pages/dec4f3f00e71a312/#directories-lib" class="sidebar-link">directories.lib</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/dec4f3f00e71a312/#directories-bin" class="sidebar-link">directories.bin</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/dec4f3f00e71a312/#directories-man" class="sidebar-link">directories.man</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/dec4f3f00e71a312/#directories-doc" class="sidebar-link">directories.doc</a></li><li class="sidebar-sub-header level3"><a href="/blog/pages/dec4f3f00e71a312/#directories-example" class="sidebar-link">directories.example</a></li></ul></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#repository" class="sidebar-link">repository</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#scripts" class="sidebar-link">scripts</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#config" class="sidebar-link">config</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#dependencies" class="sidebar-link">dependencies</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#urls-as-dependencies" class="sidebar-link">URLs as Dependencies</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#git-urls-as-dependencies" class="sidebar-link">Git URLs as Dependencies</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#github-urls" class="sidebar-link">GitHub URLs</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#local-paths" class="sidebar-link">Local Paths</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#devdependencies" class="sidebar-link">devDependencies</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#peerdependencies" class="sidebar-link">peerDependencies</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#bundleddependencies" class="sidebar-link">bundledDependencies</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#optionaldependencies" class="sidebar-link">optionalDependencies</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#engines" class="sidebar-link">engines</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#enginestrict" class="sidebar-link">engineStrict</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#os" class="sidebar-link">os</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#cpu" class="sidebar-link">cpu</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#preferglobal" class="sidebar-link">preferGlobal</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#private" class="sidebar-link">private</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#publishconfig" class="sidebar-link">publishConfig</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#default-values" class="sidebar-link">DEFAULT VALUES</a></li><li class="sidebar-sub-header level2"><a href="/blog/pages/dec4f3f00e71a312/#参考文档列表-https-docs-npmjs-com" class="sidebar-link">参考文档列表(https://docs.npmjs.com/)</a></li></ul></li><li><a href="/blog/pages/4e8444e2d534d14f/" class="sidebar-link">yaml语言教程</a></li><li><a href="/blog/pages/922650/" class="sidebar-link">Git修改分支名</a></li></ul></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>GitHub技巧</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>Nodejs</span> <span class="arrow right"></span></p> <!----></section></li><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading"><span>博客搭建</span> <span class="arrow right"></span></p> <!----></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="articleInfo-wrap" data-v-06970110><div class="articleInfo" data-v-06970110><ul class="breadcrumbs" data-v-06970110><li data-v-06970110><a href="/blog/" title="首页" class="iconfont icon-home router-link-active" data-v-06970110></a></li> <li data-v-06970110><a href="/blog/technology/#技术" data-v-06970110>技术</a></li><li data-v-06970110><a href="/blog/technology/#技术文档" data-v-06970110>技术文档</a></li></ul> <div class="info" data-v-06970110><div title="作者" class="author iconfont icon-touxiang" data-v-06970110><a href="https://github.com/heBody" target="_blank" title="作者" class="beLink" data-v-06970110>heBody</a></div> <div title="创建时间" class="date iconfont icon-riqi" data-v-06970110><a href="javascript:;" data-v-06970110>2020-04-08</a></div> <!----></div></div></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAAXNSR0IArs4c6QAABH1JREFUSA3tVl1oHFUUPmdmd2ltklqbpJDiNnXFmgbFktho7YMPNiJSSZM0+CAYSkUELVhM6YuwIPpgoOKDqOBDC0XE2CQoNtQXBUFTTcCi+Wlh1V2TQExsUzcltd3M9Tt3ZjZzZ2fT+OJTL8yeM+eee757fmeJbq//KQL8X3DUSFOcfr7cRsRtxNQMWueeVzOkaITIGqQHNg5y8+jNW9ldM7A6nTpAjuolUikAwq7CE3WcM2RRDz+XGVgN3FptU/aUSlvq9Pa3iZ1+sgAqJyyAFqkipd9dqiwHF3P65YycLWc/6sqGrvoEoIp6DOFaX5h6+dnfjkWprwqsPk0dUGq5vySwDImC10KxFHgGL1SWoc92O3eVht09qdXNH11I2SsTsJYqMWzihqGMi+A+Garf3BAuuLI5oGlULyNfyB/HYNujwktOfRrMr5t77NmevqaUopx0grnKAyvVpmwUDB4x6FPXuGvYLTDwWsejwgtgkYKPqRJg8SV6xaiZ3ZTppGneS4yfH5/66fZSDHv+QZci/+h5c5UHtpy67JUqGppM0sh0Nc1dW6/N1W5Yoqat8/TU/VnadmdeW2PLLSyh0cvxBs3KbqTmwYPpxN4do/mzE8nEpvX/UMu2Wbp74zUAK5q6WkHns7V0eWkdPbPzd3rxkTGybadYySumVzhcaJFbs5UrEkQ/+CK8gF5dnh/6ciIZ73gwQ927L1IitoxKLXYP3SjYdOrHHfTZhRRlFyrorafPk20B3HPD1y2G3qKZME5Jcf3t/HUC13/8tSd++vqFveMUTwAUxSUFI1QekR1+bIze3D9MF2aq6cPvG72CgnldWCFqyRw3lwH8ZMerjTD9ElRO7Gv44wNpC90aASqGfVlz/Rx17srQ57/UU26hkhQqUB7dBR71WmzQhHUnblGmVOEw0jhbV1n9OlXUDCIRGaNV5Jp43N516fN7JmnTHdfp7Hgy0luO4aMhtkLL8Bi3bUWYvzh5Mn1dTxrL6QmGuRhGL/TiTTxRoEdTszSaq9GR0NGA3KdkOz3hqSV3MIDhQ5IVX/Ivx3umBti2es2h4eZby7x8br1rkf7Mo90AqC8aQ3sJeNzqFRu+vSANAQe3PL7l0HGOAdwDCeZYvNKeoZp1Qfs6Aipndh86HmFRi0LAnEO47wsqM6cdfjh3jBPUzhZy7nvlUfFsamED1VQt6aISHVymXZ/B2aCtIG8AI8xfobj2d3en1wWVhOeHELKmLQ1s211s88comkv4UCwWyF787mJdYXtNfhKAXVqnKTq8QZvGAGGOfaTo5pGZ/PwbUCr5+DPr/1J92JNHr9aOl/F3iI5+O1nfybsGxoimvZ3ViWSluDITw3P37mypheDIPY0tw7+O/5ApbkYw+zpfaUVu32Pi98+defdUhEpZkRFq0aqyNh9FuL9hpYbEm6iwi0z2REd09ZmyENEbuhjDWzKvZXTqKYaBIr3tt5kuPtQBZFvEUwHt60vfCNu41XsksH9Ij1BMMz1Y0OOunHNShFIP5868g5zeXmuLwL9T4b6Q2+KejgAAAABJRU5ErkJggg==">npm packageJson属性详解<!----></h1> <div class="theme-vdoing-content content__default"><h1 id="npm-package-json属性详解"><a href="#npm-package-json属性详解" class="header-anchor">#</a> npm package.json属性详解</h1> <blockquote><p>本文转自<a href="https://www.cnblogs.com/tzyy/p/5193811.html" target="_blank" rel="noopener noreferrer">https://www.cnblogs.com/tzyy/p/5193811.html<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>,作者:TZYY</p></blockquote> <h2 id="概述"><a href="#概述" class="header-anchor">#</a> 概述</h2> <p><code>package.json</code>必须是一个严格的json文件,而不仅仅是js里边的一个对象。其中很多属性可以通过<code>npm-config</code>来生成</p> <h2 id="name"><a href="#name" class="header-anchor">#</a> name</h2> <p><code>package.json</code>中最重要的属性是<code>name</code>和<code>version</code>两个属性,这两个属性是必须要有的,否则模块就无法被安装,这两个属性一起形成了一个npm模块的唯一标识符。模块中内容变更的同时,模块版本也应该一起变化。
- <code>name</code>属性就是你的模块名称,下面是一些命名规则:</p> <ul><li><p><code>name</code>必须小于等于214个字节,包括前缀名称在内(如 xxx/xxxmodule)。</p></li> <li><p><code>name</code>不能以"_"或"."开头</p></li> <li><p>不能含有大写字母</p></li> <li><p><code>name</code>会成为url的一部分,不能含有url非法字符</p> <p>下面是官网文档的一些建议:</p></li> <li><p>不要使用和node核心模块一样的名称</p></li> <li><p><code>name</code>中不要含有"js"和"node"。 It's assumed that it's js, since you're writing a package.json file, and you can specify the engine using the "engines" field. (See below.)</p></li> <li><p><code>name</code>属性会成为模块url、命令行中的一个参数或者一个文件夹名称,任何非url安全的字符在name中都不能使用,也不能以"_"或"."开头</p></li> <li><p><code>name</code>属性也许会被写在<code>require()</code>的参数中,所以最好取个简短而语义化的值。</p></li> <li><p>创建一个模块前可以先到后边的网址查查<code>name</code>是否已经被占用. <a href="https://www.npmjs.com/" target="_blank" rel="noopener noreferrer">https://www.npmjs.com/<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <ul><li><div class="language-sh line-numbers-mode"><pre class="language-sh"><code><span class="token comment"># 发布一个包的时候,需要检验某个包名是否存在</span>
- <span class="token function">npm</span> search <span class="token operator"><</span>ModuleName<span class="token operator">></span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br></div></div></li></ul></li></ul> <p><code>name</code>属性可以有一些前缀如 e.g. @myorg/mypackage.在npm-scope(7)的文档中可以看到详细说明</p> <h2 id="version"><a href="#version" class="header-anchor">#</a> version</h2> <p><code>version</code>必须可以被npm依赖的一个<code>node-semver</code>模块解析。具体规则见下面的<code>dependencies</code>模块</p> <h2 id="description"><a href="#description" class="header-anchor">#</a> description</h2> <p>一个描述,方便别人了解你的模块作用,搜索的时候也有用。</p> <h2 id="keywords"><a href="#keywords" class="header-anchor">#</a> keywords</h2> <p>一个字符串数组,方便别人搜索到本模块</p> <h2 id="homepage"><a href="#homepage" class="header-anchor">#</a> homepage</h2> <p>项目主页url
- <strong>注意:</strong> 这个项目主页url和url属性不同,如果你填写了url属性,npm注册工具会认为你把项目发布到其他地方了,获取模块的时候不会从npm官方仓库获取,而是会重定向到url属性配置的地址。
- (原文档中用了 spit(吐)这个单词,作者表示他不是在开玩笑:)</p> <h2 id="bugs"><a href="#bugs" class="header-anchor">#</a> bugs</h2> <p>填写一个bug提交地址或者一个邮箱,被你的模块坑到的人可以通过这里吐槽,例如:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
- <span class="token property">"url"</span> <span class="token operator">:</span> <span class="token string">"https://github.com/owner/project/issues"</span><span class="token punctuation">,</span>
- <span class="token property">"email"</span> <span class="token operator">:</span> <span class="token string">"project@hostname.com"</span>
- <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>url和email可以任意填或不填,如果只填一个,可以直接写成一个字符串而不是对象。如果填写了url,npm bugs命令会使用这个url。</p> <h2 id="license"><a href="#license" class="header-anchor">#</a> license</h2> <p>你应该为你的模块制定一个协议,让用户知道他们有何权限来使用你的模块,以及使用该模块有哪些限制。最简单的,例如你用BSD-3-Clause 或 MIT之类的协议,如下:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span> <span class="token property">"license"</span> <span class="token operator">:</span> <span class="token string">"MIT"</span> <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>你可以在<a href="https://spdx.org/licenses/" target="_blank" rel="noopener noreferrer">https://spdx.org/licenses/ <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a>这个地址查阅协议列表 。</p> <h2 id="和用户相关的属性-author-contributors"><a href="#和用户相关的属性-author-contributors" class="header-anchor">#</a> 和用户相关的属性: author, contributors</h2> <p><code>author</code>是一个码农, <code>contributors</code>是一个码农数组。 <code>person</code>是一个有一些描述属性的对象,如下 like this:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
- <span class="token property">"name"</span> <span class="token operator">:</span> <span class="token string">"Barney Rubble"</span><span class="token punctuation">,</span>
- <span class="token property">"email"</span> <span class="token operator">:</span> <span class="token string">"b@rubble.com"</span><span class="token punctuation">,</span>
- <span class="token property">"url"</span> <span class="token operator">:</span> <span class="token string">"http://barnyrubble.tumblr.com/"</span>
- <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>也可以按如下格式缩写,npm会帮着转换:</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>"Barney Rubble b@rubble.com (http://barnyrubble.tumblr.com/)"
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p><code>email</code>和<code>url</code>属性实际上都是可以省略的。描述用户信息的还有一个<code>maintainers</code>(维护者)属性。</p> <h2 id="files"><a href="#files" class="header-anchor">#</a> files</h2> <p><code>files</code>属性的值是一个数组,内容是模块下文件名或者文件夹名,如果是文件夹名,则文件夹下所有的文件也会被包含进来(除非文件被另一些配置排除了)
- 你也可以在模块根目录下创建一个<code>.npmignore</code>文件(windows下无法直接创建以"."开头的文件,使用linux命令行工具创建如git bash),写在这个文件里边的文件即便被写在files属性里边也会被排除在外,这个文件的写法".gitignore"类似。</p> <h2 id="main"><a href="#main" class="header-anchor">#</a> main</h2> <p><code>main</code>属性指定了程序的主入口文件。意思是,如果你的模块被命名为foo,用户安装了这个模块并通过require("foo")来使用这个模块,那么require返回的内容就是main属性指定的文件中 module.exports指向的对象。
- 它应该指向模块根目录下的一个文件。对大对数模块而言,这个属性更多的是让模块有一个主入口文件,然而很多模块并不写这个属性。</p> <h2 id="bin"><a href="#bin" class="header-anchor">#</a> bin</h2> <p>很多模块有一个或多个需要配置到PATH路径下的可执行模块,npm让这个工作变得十分简单(实际上npm本身也是通过bin属性安装为一个可执行命令的)
- 如果要用npm的这个功能,在package.json里边配置一个bin属性。bin属性是一个已命令名称为key,本地文件名称为value的map如下:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
- <span class="token property">"bin"</span> <span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"myapp"</span> <span class="token operator">:</span> <span class="token string">"./cli.js"</span> <span class="token punctuation">}</span>
- <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br></div></div><p>模块安装的时候,若是全局安装,则npm会为bin中配置的文件在bin目录下创建一个软连接(对于windows系统,默认会在C:\Users\username\AppData\Roaming\npm目录下),若是局部安装,则会在项目内的./node_modules/.bin/目录下创建一个软链接。
- 因此,按上面的例子,当你安装myapp的时候,npm就会为cli.js在/usr/local/bin/myapp路径创建一个软链接。
- 如果你的模块只有一个可执行文件,并且它的命令名称和模块名称一样,你可以只写一个字符串来代替上面那种配置,例如:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
- <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"my-program"</span><span class="token punctuation">,</span>
- <span class="token property">"version"</span><span class="token operator">:</span> <span class="token string">"1.2.5"</span><span class="token punctuation">,</span>
- <span class="token property">"bin"</span><span class="token operator">:</span> <span class="token string">"./path/to/program"</span>
- <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>作用和如下写法相同:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
- <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"my-program"</span><span class="token punctuation">,</span>
- <span class="token property">"version"</span><span class="token operator">:</span> <span class="token string">"1.2.5"</span><span class="token punctuation">,</span>
- <span class="token property">"bin"</span> <span class="token operator">:</span> <span class="token punctuation">{</span>
- <span class="token property">"my-program"</span> <span class="token operator">:</span> <span class="token string">"./path/to/program"</span>
- <span class="token punctuation">}</span>
- <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h2 id="man"><a href="#man" class="header-anchor">#</a> man</h2> <p>制定一个或通过数组制定一些文件来让linux下的man命令查找文档地址。
- 如果只有一个文件被指定的话,安装后直接使用man+模块名称,而不管man指定的文件的实际名称。例如:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
- <span class="token property">"name"</span> <span class="token operator">:</span> <span class="token string">"foo"</span><span class="token punctuation">,</span>
- <span class="token property">"version"</span> <span class="token operator">:</span> <span class="token string">"1.2.3"</span><span class="token punctuation">,</span>
- <span class="token property">"description"</span> <span class="token operator">:</span> <span class="token string">"A packaged foo fooer for fooing foos"</span><span class="token punctuation">,</span>
- <span class="token property">"main"</span> <span class="token operator">:</span> <span class="token string">"foo.js"</span><span class="token punctuation">,</span>
- <span class="token property">"man"</span> <span class="token operator">:</span> <span class="token string">"./man/doc.1"</span>
- <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>通过man foo命令会得到 ./man/doc.1 文件的内容。
- 如果man文件名称不是以模块名称开头的,安装的时候会给加上模块名称前缀。因此,下面这段配置:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
- <span class="token property">"name"</span> <span class="token operator">:</span> <span class="token string">"foo"</span><span class="token punctuation">,</span>
- <span class="token property">"version"</span> <span class="token operator">:</span> <span class="token string">"1.2.3"</span><span class="token punctuation">,</span>
- <span class="token property">"description"</span> <span class="token operator">:</span> <span class="token string">"A packaged foo fooer for fooing foos"</span><span class="token punctuation">,</span>
- <span class="token property">"main"</span> <span class="token operator">:</span> <span class="token string">"foo.js"</span><span class="token punctuation">,</span>
- <span class="token property">"man"</span> <span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token string">"./man/foo.1"</span><span class="token punctuation">,</span> <span class="token string">"./man/bar.1"</span> <span class="token punctuation">]</span>
- <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>会创建一些文件来作为man foo和man foo-bar命令的结果。
- man文件必须以数字结尾,或者如果被压缩了,以.gz结尾。数字表示文件将被安装到man的哪个部分。</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
- <span class="token property">"name"</span> <span class="token operator">:</span> <span class="token string">"foo"</span><span class="token punctuation">,</span>
- <span class="token property">"version"</span> <span class="token operator">:</span> <span class="token string">"1.2.3"</span><span class="token punctuation">,</span>
- <span class="token property">"description"</span> <span class="token operator">:</span> <span class="token string">"A packaged foo fooer for fooing foos"</span><span class="token punctuation">,</span>
- <span class="token property">"main"</span> <span class="token operator">:</span> <span class="token string">"foo.js"</span><span class="token punctuation">,</span>
- <span class="token property">"man"</span> <span class="token operator">:</span> <span class="token punctuation">[</span> <span class="token string">"./man/foo.1"</span><span class="token punctuation">,</span> <span class="token string">"./man/foo.2"</span> <span class="token punctuation">]</span>
- <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>会创建 man foo 和 man 2 foo 两条命令。</p> <h2 id="directories"><a href="#directories" class="header-anchor">#</a> directories</h2> <p>CommonJs通过directories来制定一些方法来描述模块的结构,看看npm的package.json文件https://registry.npmjs.org/npm/latest ,可以发现里边有这个字段的内容。
- <img src="http://zoucz.com/blogimgs/2016-02-16/1455624810992.png" alt="img">
- 目前这个配置没有任何作用,将来可能会整出一些花样来。</p> <h3 id="directories-lib"><a href="#directories-lib" class="header-anchor">#</a> directories.lib</h3> <p>告诉用户模块中lib目录在哪,这个配置目前没有任何作用,但是对使用模块的人来说是一个很有用的信息。</p> <h3 id="directories-bin"><a href="#directories-bin" class="header-anchor">#</a> directories.bin</h3> <p>如果你在这里指定了bin目录,这个配置下面的文件会被加入到bin路径下,如果你已经在package.json中配置了bin目录,那么这里的配置将不起任何作用。</p> <h3 id="directories-man"><a href="#directories-man" class="header-anchor">#</a> directories.man</h3> <p>指定一个目录,目录里边都是man文件,这是一种配置man文件的语法糖。</p> <h3 id="directories-doc"><a href="#directories-doc" class="header-anchor">#</a> directories.doc</h3> <p>在这个目录里边放一些markdown文件,可能最终有一天它们会被友好的展现出来(应该是在npm的网站上)</p> <h3 id="directories-example"><a href="#directories-example" class="header-anchor">#</a> directories.example</h3> <p>放一些示例脚本,或许某一天会有用 - -!</p> <h2 id="repository"><a href="#repository" class="header-anchor">#</a> repository</h2> <p>指定一个代码存放地址,对想要为你的项目贡献代码的人有帮助。像这样:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token property">"repository"</span> <span class="token operator">:</span>
- <span class="token punctuation">{</span>
- <span class="token property">"type"</span> <span class="token operator">:</span> <span class="token string">"git"</span><span class="token punctuation">,</span>
- <span class="token property">"url"</span> <span class="token operator">:</span> <span class="token string">"https://github.com/npm/npm.git"</span>
- <span class="token punctuation">}</span>
- <span class="token property">"repository"</span> <span class="token operator">:</span>
- <span class="token punctuation">{</span>
- <span class="token property">"type"</span> <span class="token operator">:</span> <span class="token string">"svn"</span><span class="token punctuation">,</span>
- <span class="token property">"url"</span> <span class="token operator">:</span> <span class="token string">"https://v8.googlecode.com/svn/trunk/"</span>
- <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p>若你的模块放在GitHub, GitHub gist, Bitbucket, or GitLab的仓库里,npm install的时候可以使用缩写标记来完成:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token property">"repository"</span><span class="token operator">:</span> <span class="token string">"npm/npm"</span>
- <span class="token property">"repository"</span><span class="token operator">:</span> <span class="token string">"gist:11081aaa281"</span>
- <span class="token property">"repository"</span><span class="token operator">:</span> <span class="token string">"bitbucket:example/repo"</span>
- <span class="token property">"repository"</span><span class="token operator">:</span> <span class="token string">"gitlab:another/repo"</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><h2 id="scripts"><a href="#scripts" class="header-anchor">#</a> scripts</h2> <p>scripts属性是一个对象,里边指定了项目的生命周期个各个环节需要执行的命令。key是生命周期中的事件,value是要执行的命令。
- 具体的内容有 install start stop 等,详见<a href="https://docs.npmjs.com/misc/scripts" target="_blank" rel="noopener noreferrer"> https://docs.npmjs.com/misc/scripts<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <h2 id="config"><a href="#config" class="header-anchor">#</a> config</h2> <p>用来设置一些项目不怎么变化的项目配置,例如port等。
- 用户用的时候可以使用如下用法:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code>http.createServer(...).listen(process.env.npm_package_config_port)
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br></div></div><p>可以通过npm config set foo:port 80来修改config。详见<a href="https://docs.npmjs.com/misc/config" target="_blank" rel="noopener noreferrer">https://docs.npmjs.com/misc/config<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
- <span class="token property">"name"</span> <span class="token operator">:</span> <span class="token string">"foo"</span><span class="token punctuation">,</span>
- <span class="token property">"config"</span> <span class="token operator">:</span> <span class="token punctuation">{</span> <span class="token property">"port"</span> <span class="token operator">:</span> <span class="token string">"8080"</span> <span class="token punctuation">}</span>
- <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><h2 id="dependencies"><a href="#dependencies" class="header-anchor">#</a> dependencies</h2> <p>dependencies属性是一个对象,配置模块依赖的模块列表,key是模块名称,value是版本范围,版本范围是一个字符,可以被一个或多个空格分割。
- dependencies也可以被指定为一个git地址或者一个压缩包地址。
- 不要把测试工具或transpilers写到dependencies中。 下面是一些写法,详见<a href="https://docs.npmjs.com/misc/semver" target="_blank" rel="noopener noreferrer">https://docs.npmjs.com/misc/semver<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p> <ul><li>version 精确匹配版本</li> <li>>version 必须大于某个版本</li> <li>>=version 大于等于</li> <li><version 小于</li> <li><=versionversion 小于</li> <li>~version "约等于",具体规则详见semver文档</li> <li>^version "兼容版本"具体规则详见semver文档</li> <li>1.2.x 仅一点二点几的版本</li> <li>http://... 见下面url作为denpendencies的说明</li> <li><ul><li>任何版本</li></ul></li> <li>"" 空字符,和*相同</li> <li>version1 - version2 相当于 >=version1 <=version2.</li> <li>range1 || range2 范围1和范围2满足任意一个都行</li> <li>git... 见下面git url作为denpendencies的说明</li> <li>user/repo See 见下面GitHub仓库的说明</li> <li>tag 发布的一个特殊的标签,见npm-tag的文档 <a href="https://docs.npmjs.com/getting-started/using-tags" target="_blank" rel="noopener noreferrer">https://docs.npmjs.com/getting-started/using-tags<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li> <li>path/path/path 见下面本地模块的说明
- 下面的写法都是可以的:</li></ul> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span> <span class="token property">"dependencies"</span> <span class="token operator">:</span>
- <span class="token punctuation">{</span> <span class="token property">"foo"</span> <span class="token operator">:</span> <span class="token string">"1.0.0 - 2.9999.9999"</span>
- <span class="token punctuation">,</span> <span class="token property">"bar"</span> <span class="token operator">:</span> <span class="token string">">=1.0.2 <2.1.2"</span>
- <span class="token punctuation">,</span> <span class="token property">"baz"</span> <span class="token operator">:</span> <span class="token string">">1.0.2 <=2.3.4"</span>
- <span class="token punctuation">,</span> <span class="token property">"boo"</span> <span class="token operator">:</span> <span class="token string">"2.0.1"</span>
- <span class="token punctuation">,</span> <span class="token property">"qux"</span> <span class="token operator">:</span> <span class="token string">"<1.0.0 || >=2.3.1 <2.4.5 || >=2.5.2 <3.0.0"</span>
- <span class="token punctuation">,</span> <span class="token property">"asd"</span> <span class="token operator">:</span> <span class="token string">"http://asdf.com/asdf.tar.gz"</span>
- <span class="token punctuation">,</span> <span class="token property">"til"</span> <span class="token operator">:</span> <span class="token string">"~1.2"</span>
- <span class="token punctuation">,</span> <span class="token property">"elf"</span> <span class="token operator">:</span> <span class="token string">"~1.2.3"</span>
- <span class="token punctuation">,</span> <span class="token property">"two"</span> <span class="token operator">:</span> <span class="token string">"2.x"</span>
- <span class="token punctuation">,</span> <span class="token property">"thr"</span> <span class="token operator">:</span> <span class="token string">"3.3.x"</span>
- <span class="token punctuation">,</span> <span class="token property">"lat"</span> <span class="token operator">:</span> <span class="token string">"latest"</span>
- <span class="token punctuation">,</span> <span class="token property">"dyl"</span> <span class="token operator">:</span> <span class="token string">"file:../dyl"</span>
- <span class="token punctuation">}</span>
- <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><h2 id="urls-as-dependencies"><a href="#urls-as-dependencies" class="header-anchor">#</a> URLs as Dependencies</h2> <p>在版本范围的地方可以写一个url指向一个压缩包,模块安装的时候会把这个压缩包下载下来安装到模块本地。</p> <h2 id="git-urls-as-dependencies"><a href="#git-urls-as-dependencies" class="header-anchor">#</a> Git URLs as Dependencies</h2> <p>Git url可以像下面一样:</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>git://github.com/user/project.git#commit-ish
- git+ssh://user@hostname:project.git#commit-ish
- git+ssh://user@hostname/project.git#commit-ish
- git+http://user@hostname/project/blah.git#commit-ish
- git+https://user@hostname/project/blah.git#commit-ish
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><p>commit-ish 可以是任意标签,哈希值,或者可以检出的分支,默认是master分支。</p> <h2 id="github-urls"><a href="#github-urls" class="header-anchor">#</a> GitHub URLs</h2> <p>支持github的 username/modulename 的写法,#后边可以加后缀写明分支hash或标签:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
- <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"foo"</span><span class="token punctuation">,</span>
- <span class="token property">"version"</span><span class="token operator">:</span> <span class="token string">"0.0.0"</span><span class="token punctuation">,</span>
- <span class="token property">"dependencies"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
- <span class="token property">"express"</span><span class="token operator">:</span> <span class="token string">"visionmedia/express"</span><span class="token punctuation">,</span>
- <span class="token property">"mocha"</span><span class="token operator">:</span> <span class="token string">"visionmedia/mocha#4727d357ea"</span>
- <span class="token punctuation">}</span>
- <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br></div></div><h2 id="local-paths"><a href="#local-paths" class="header-anchor">#</a> Local Paths</h2> <p>npm2.0.0版本以上可以提供一个本地路径来安装一个本地的模块,通过npm install xxx --save 来安装,格式如下:</p> <div class="language- line-numbers-mode"><pre class="language-text"><code>../foo/bar
- ~/foo/bar
- ./foo/bar
- /foo/bar
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br></div></div><p>package.json 生成的相对路径如下:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
- <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"baz"</span><span class="token punctuation">,</span>
- <span class="token property">"dependencies"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
- <span class="token property">"bar"</span><span class="token operator">:</span> <span class="token string">"file:../foo/bar"</span>
- <span class="token punctuation">}</span>
- <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br></div></div><p>这种属性在离线开发或者测试需要用npm install的情况,又不想自己搞一个npm server的时候有用,但是发布模块到公共仓库时不应该使用这种属性。</p> <h2 id="devdependencies"><a href="#devdependencies" class="header-anchor">#</a> devDependencies</h2> <p>如果有人想要下载并使用你的模块,也许他们并不希望或需要下载一些你在开发过程中使用的额外的测试或者文档框架。
- 在这种情况下,最好的方法是把这些依赖添加到devDependencies属性的对象中。
- 这些模块会在npm link或者npm install的时候被安装,也可以像其他npm配置一样被管理,详见npm的config文档。
- 对于一些跨平台的构建任务,例如把CoffeeScript编译成JavaScript,就可以通过在package.json的script属性里边配置prepublish脚本来完成这个任务,然后需要依赖的coffee-script模块就写在devDependencies属性种。
- 例如:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span> <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"ethopia-waza"</span><span class="token punctuation">,</span>
- <span class="token property">"description"</span><span class="token operator">:</span> <span class="token string">"a delightfully fruity coffee varietal"</span><span class="token punctuation">,</span>
- <span class="token property">"version"</span><span class="token operator">:</span> <span class="token string">"1.2.3"</span><span class="token punctuation">,</span>
- <span class="token property">"devDependencies"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
- <span class="token property">"coffee-script"</span><span class="token operator">:</span> <span class="token string">"~1.6.3"</span>
- <span class="token punctuation">}</span><span class="token punctuation">,</span>
- <span class="token property">"scripts"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
- <span class="token property">"prepublish"</span><span class="token operator">:</span> <span class="token string">"coffee -o lib/ -c src/waza.coffee"</span>
- <span class="token punctuation">}</span><span class="token punctuation">,</span>
- <span class="token property">"main"</span><span class="token operator">:</span> <span class="token string">"lib/waza.js"</span>
- <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br></div></div><p>prepublish脚本会在发布之前运行,因此用户在使用之前就不用再自己去完成编译的过程了。在开发模式下,运行npm install也会执行这个脚本(见npm script文档),因此可以很方便的调试。</p> <h2 id="peerdependencies"><a href="#peerdependencies" class="header-anchor">#</a> peerDependencies</h2> <p>有时候做一些插件开发,比如grunt等工具的插件,它们往往是在grunt的某个版本的基础上开发的,而在他们的代码中并不会出现require("grunt")这样的依赖,dependencies配置里边也不会写上grunt的依赖,为了说明此模块只能作为插件跑在宿主的某个版本范围下,可以配置peerDependencies:</p> <div class="language-json line-numbers-mode"><pre class="language-json"><code><span class="token punctuation">{</span>
- <span class="token property">"name"</span><span class="token operator">:</span> <span class="token string">"tea-latte"</span><span class="token punctuation">,</span>
- <span class="token property">"version"</span><span class="token operator">:</span> <span class="token string">"1.3.5"</span><span class="token punctuation">,</span>
- <span class="token property">"peerDependencies"</span><span class="token operator">:</span> <span class="token punctuation">{</span>
- <span class="token property">"tea"</span><span class="token operator">:</span> <span class="token string">"2.x"</span>
- <span class="token punctuation">}</span>
- <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br></div></div><p>上面这个配置确保再npm install的时候tea-latte会和2.x版本的tea一起安装,而且它们两个的依赖关系是同级的:
- ├── tea-latte@1.3.5
- └── tea@2.2.0
- 这个配置的目的是让npm知道,如果要使用此插件模块,请确保安装了兼容版本的宿主模块。</p> <h2 id="bundleddependencies"><a href="#bundleddependencies" class="header-anchor">#</a> bundledDependencies</h2> <p>上面的单词少个d,写成bundleDependencies也可以。
- 指定发布的时候会被一起打包的模块。</p> <h2 id="optionaldependencies"><a href="#optionaldependencies" class="header-anchor">#</a> optionalDependencies</h2> <p>如果一个依赖模块可以被使用, 同时你也希望在该模块找不到或无法获取时npm继续运行,你可以把这个模块依赖放到optionalDependencies配置中。这个配置的写法和dependencies的写法一样,不同的是这里边写的模块安装失败不会导致npm install失败。
- 当然,这种模块就需要你自己在代码中处理模块确实的情况了,例如:</p> <div class="language-js line-numbers-mode"><pre class="language-js"><code><span class="token keyword">try</span> <span class="token punctuation">{</span>
- <span class="token keyword">var</span> foo <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'foo'</span><span class="token punctuation">)</span>
- <span class="token keyword">var</span> fooVersion <span class="token operator">=</span> <span class="token function">require</span><span class="token punctuation">(</span><span class="token string">'foo/package.json'</span><span class="token punctuation">)</span><span class="token punctuation">.</span>version
- <span class="token punctuation">}</span> <span class="token keyword">catch</span> <span class="token punctuation">(</span>er<span class="token punctuation">)</span> <span class="token punctuation">{</span>
- foo <span class="token operator">=</span> <span class="token keyword">null</span>
- <span class="token punctuation">}</span>
- <span class="token keyword">if</span> <span class="token punctuation">(</span> <span class="token function">notGoodFooVersion</span><span class="token punctuation">(</span>fooVersion<span class="token punctuation">)</span> <span class="token punctuation">)</span> <span class="token punctuation">{</span>
- foo <span class="token operator">=</span> <span class="token keyword">null</span>
- <span class="token punctuation">}</span>
- <span class="token comment">// .. then later in your program ..</span>
- <span class="token keyword">if</span> <span class="token punctuation">(</span>foo<span class="token punctuation">)</span> <span class="token punctuation">{</span>
- foo<span class="token punctuation">.</span><span class="token function">doFooThings</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
- <span class="token punctuation">}</span>
- </code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br></div></div><p>optionalDependencies 中的配置会覆盖dependencies中的配置,最好只在一个地方写。</p> <h2 id="engines"><a href="#engines" class="header-anchor">#</a> engines</h2> <p>你可以指定项目运行的node版本范围,如下:
- { "engines" : { "node" : ">=0.10.3 <0.12" } }
- 和dependencies一样,如果你不指定版本范围或者指定为*,任何版本的node都可以。
- 也可以指定一些npm版本可以正确的安装你的模块,例如:
- { "engines" : { "npm" : "~1.0.20" } }
- 要注意的是,除非你设置了engine-strict属性,engines属性是仅供参考的。</p> <h2 id="enginestrict"><a href="#enginestrict" class="header-anchor">#</a> engineStrict</h2> <p>注意:这个属性已经弃用,将在npm 3.0.0 版本干掉。</p> <h2 id="os"><a href="#os" class="header-anchor">#</a> os</h2> <p>可以指定你的模块只能在哪个操作系统上跑:
- "os" : [ "darwin", "linux" ]
- 也可以指定黑名单而不是白名单:
- "os" : [ "!win32" ]
- 服务的操作系统是由process.platform来判断的,这个属性允许黑白名单同时存在,虽然没啥必要这样搞...</p> <h2 id="cpu"><a href="#cpu" class="header-anchor">#</a> cpu</h2> <p>限制模块只能在某某cpu架构下运行
- "cpu" : [ "x64", "ia32" ]
- 同样可以设置黑名单:
- "cpu" : [ "!arm", "!mips" ]
- cpu架构通过 process.arch 判断</p> <h2 id="preferglobal"><a href="#preferglobal" class="header-anchor">#</a> preferGlobal</h2> <p>如果您的软件包主要用于安装到全局的命令行应用程序,那么该值设置为true ,如果它被安装在本地,则提供一个警告。实际上该配置并没有阻止用户把模块安装到本地,只是防止该模块被错误的使用引起一些问题。</p> <h2 id="private"><a href="#private" class="header-anchor">#</a> private</h2> <p>如果这个属性被设置为true,npm将拒绝发布它,这是为了防止一个私有模块被无意间发布出去。如果你只想让模块被发布到一个特定的npm仓库,如一个内部的仓库,可与在下面的publishConfig中配置仓库参数。</p> <h2 id="publishconfig"><a href="#publishconfig" class="header-anchor">#</a> publishConfig</h2> <p>这个配置是会在模块发布时用到的一些值的集合。如果你不想模块被默认被标记为最新的,或者默认发布到公共仓库,可以在这里配置tag或仓库地址。</p> <h2 id="default-values"><a href="#default-values" class="header-anchor">#</a> DEFAULT VALUES</h2> <p>npm设置了一些默认参数,如:
- "scripts": {"start": "node server.js"}
- 如果模块根目录下有一个server.js文件,那么npm start会默认运行这个文件。
- "scripts":{"preinstall": "node-gyp rebuild"}
- 如果模块根目录下有binding.gyp, npm将默认用node-gyp来编译preinstall的脚本
- "contributors": [...]
- 若模块根目录下有AUTHORS 文件,则npm会按Name (url)格式解析每一行的数据添加到contributors中,可以用#添加行注释</p> <h2 id="参考文档列表-https-docs-npmjs-com"><a href="#参考文档列表-https-docs-npmjs-com" class="header-anchor">#</a> 参考文档列表(https://docs.npmjs.com/)</h2> <p>semver(7)
- npm-init(1)
- npm-version(1)
- npm-config(1)
- npm-config(7)
- npm-help(1)
- npm-faq(7)
- npm-install(1)
- npm-publish(1)
- npm-rm(1)</p></div></div> <div class="page-edit"><div class="edit-link"><a href="https://github.com/heBody/blog/edit/master/docs/03.技术/01.技术文档/10.npm packageJson属性详解.md" target="_blank" rel="noopener noreferrer">编辑</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2022/12/14, 19:36:42</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/blog/pages/61f2f95fd7da14fd/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">npm常用命令</div></a> <a href="/blog/pages/4e8444e2d534d14f/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">yaml语言教程</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
- ←
- <a href="/blog/pages/61f2f95fd7da14fd/" class="prev">npm常用命令</a></span> <span class="next"><a href="/blog/pages/4e8444e2d534d14f/">yaml语言教程</a>→
- </span></p></div></div></div> <div class="article-list"><div class="article-title"><a href="/blog/archives/" class="iconfont icon-bi">最近更新</a></div> <div class="article-wrapper"><dl><dd>01</dd> <dt><a href="/blog/pages/922650/"><div>
- Git修改分支名
- <!----></div></a> <span class="date">08-11</span></dt></dl><dl><dd>02</dd> <dt><a href="/blog/pages/55f894/"><div>
- CSS给table的tbody添加滚动条
- <!----></div></a> <span class="date">06-29</span></dt></dl><dl><dd>03</dd> <dt><a href="/blog/pages/829589/"><div>
- 我做了一个手写春联小网页,祝大家虎年暴富
- <span class="title-tag">
- 原创
- </span></div></a> <span class="date">01-28</span></dt></dl> <dl><dd></dd> <dt><a href="/blog/archives/" class="more">更多文章></a></dt></dl></div></div></main></div> <div class="footer"><div class="icons"><a href="mailto:30363811@qq.com" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://github.com/heBody" title="GitHub" target="_blank" class="iconfont icon-github"></a></div>
- Copyright © 2016-2022
- <span>Hesb | <a href="https://github.com/heBody/blob" target="_blank">MIT License</a></span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
- 跟随系统
- </li><li class="iconfont icon-rijianmoshi">
- 浅色模式
- </li><li class="iconfont icon-yejianmoshi">
- 深色模式
- </li><li class="iconfont icon-yuedu">
- 阅读模式
- </li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"><div></div></div></div>
- <script src="/blog/assets/js/app.90754bd5.js" defer></script><script src="/blog/assets/js/2.106f41fb.js" defer></script><script src="/blog/assets/js/3.6748bd5c.js" defer></script><script src="/blog/assets/js/54.dbb7c9ab.js" defer></script>
- </body>
- </html>
|