{"id":8880,"date":"2023-08-30T14:44:38","date_gmt":"2023-08-30T06:44:38","guid":{"rendered":"\/?p=8880"},"modified":"2023-08-30T14:44:38","modified_gmt":"2023-08-30T06:44:38","slug":"npm%e5%b8%b8%e7%94%a8%e6%8c%87%e4%bb%a4","status":"publish","type":"post","link":"\/?p=8880","title":{"rendered":"npm\u5e38\u7528\u6307\u4ee4"},"content":{"rendered":"<h2>npm\u662f\u4ec0\u4e48<\/h2>\n<p>NPM\u7684\u5168\u79f0\u662fNode Package Manager\uff0c\u662f\u968f\u540cNodeJS\u4e00\u8d77\u5b89\u88c5\u7684\u5305\u7ba1\u7406\u548c\u5206\u53d1\u5de5\u5177\uff0c\u5b83\u5f88\u65b9\u4fbf\u8ba9JavaScript\u5f00\u53d1\u8005\u4e0b\u8f7d\u3001\u5b89\u88c5\u3001\u4e0a\u4f20\u4ee5\u53ca\u7ba1\u7406\u5df2\u7ecf\u5b89\u88c5\u7684\u5305\u3002<\/p>\n<h2>npm install \u5b89\u88c5\u6a21\u5757<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code class=\"language-shell\">npm install (with no args, in package dir)\nnpm install [&lt;@scope&gt;\/]&lt;name&gt;\nnpm install [&lt;@scope&gt;\/]&lt;name&gt;@&lt;tag&gt;\nnpm install [&lt;@scope&gt;\/]&lt;name&gt;@&lt;version&gt;\nnpm install [&lt;@scope&gt;\/]&lt;name&gt;@&lt;version range&gt;\nnpm install &lt;tarball file&gt;\nnpm install &lt;tarball url&gt;\nnpm install &lt;folder&gt;\n\nalias: npm i\ncommon options: [-S|--save|-D|--save-dev|-O|--save-optional] [-E|--save-exact] [--dry-run]<\/code><\/pre>\n<p>\u5b89\u88c5\u5305\uff0c\u9ed8\u8ba4\u4f1a\u5b89\u88c5\u6700\u65b0\u7684\u7248\u672c<\/p>\n<pre><code>npm install gulp<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/278431-20160612163826965-609701972.png\" alt=\"img\" \/><\/p>\n<p>\u5b89\u88c5\u6307\u5b9a\u7248\u672c<\/p>\n<pre><code>npm install gulp@3.9.1<\/code><\/pre>\n<p>\u5b89\u88c5\u5305\u5e76\u5c06\u4fe1\u606f\u4fdd\u6301\u5230\u9879\u76ee\u7684package.json\u6587\u4ef6\u4e2d<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/278431-20160608175914183-728696602.jpg\" alt=\"img\" \/><\/p>\n<p>\u9879\u76ee\u5bf9\u6a21\u5757\u7684\u4f9d\u8d56\u53ef\u4ee5\u4f7f\u7528\u4e0b\u9762\u7684 3 \u79cd\u65b9\u6cd5\u6765\u8868\u793a\uff08\u5047\u8bbe\u5f53\u524d\u7248\u672c\u53f7\u662f 1.1.0 \uff09\uff1a<\/p>\n<ul>\n<li>\u517c\u5bb9\u6a21\u5757\u65b0\u53d1\u5e03\u7684\u8865\u4e01\u7248\u672c\uff1a~1.1.0\u30011.1.x\u30011.1<\/li>\n<li>\u517c\u5bb9\u6a21\u5757\u65b0\u53d1\u5e03\u7684\u5c0f\u7248\u672c\u3001\u8865\u4e01\u7248\u672c\uff1a^1.1.0\u30011.x\u30011<\/li>\n<li>\u517c\u5bb9\u6a21\u5757\u65b0\u53d1\u5e03\u7684\u5927\u7248\u672c\u3001\u5c0f\u7248\u672c\u3001\u8865\u4e01\u7248\u672c\uff1a*\u3001x<\/li>\n<\/ul>\n<p><strong>-S, --save \u5b89\u88c5\u5305\u4fe1\u606f\u5c06\u52a0\u5165\u5230dependencies\uff08\u751f\u4ea7\u9636\u6bb5\u7684\u4f9d\u8d56\uff09<\/strong><\/p>\n<pre><code>npm install gulp --save \u6216 npm install gulp -S<\/code><\/pre>\n<p>package.json \u6587\u4ef6\u7684 dependencies \u5b57\u6bb5\uff1a<\/p>\n<pre><code>&quot;dependencies&quot;: {\n    &quot;gulp&quot;: &quot;^3.9.1&quot;\n}<\/code><\/pre>\n<p><strong>-D, --save-dev \u5b89\u88c5\u5305\u4fe1\u606f\u5c06\u52a0\u5165\u5230devDependencies\uff08\u5f00\u53d1\u9636\u6bb5\u7684\u4f9d\u8d56\uff09\uff0c\u6240\u4ee5\u5f00\u53d1\u9636\u6bb5\u4e00\u822c\u4f7f\u7528\u5b83<\/strong><\/p>\n<pre><code>npm install gulp --save-dev \u6216 npm install gulp -D<\/code><\/pre>\n<p>package.json \u6587\u4ef6\u7684 devDependencies\u5b57\u6bb5\uff1a<\/p>\n<pre><code>&quot;devDependencies&quot;: {\n    &quot;gulp&quot;: &quot;^3.9.1&quot;\n}<\/code><\/pre>\n<p><strong>-O, --save-optional \u5b89\u88c5\u5305\u4fe1\u606f\u5c06\u52a0\u5165\u5230optionalDependencies\uff08\u53ef\u9009\u9636\u6bb5\u7684\u4f9d\u8d56\uff09<\/strong><\/p>\n<pre><code>npm install gulp --save-optional \u6216 npm install gulp -O<\/code><\/pre>\n<p>package.json \u6587\u4ef6\u7684optionalDependencies\u5b57\u6bb5\uff1a<\/p>\n<pre><code>&quot;optionalDependencies&quot;: {\n    &quot;gulp&quot;: &quot;^3.9.1&quot;\n}<\/code><\/pre>\n<p><strong>-E, --save-exact \u7cbe\u786e\u5b89\u88c5\u6307\u5b9a\u6a21\u5757\u7248\u672c<\/strong><\/p>\n<pre><code>npm install gulp --save-exact \u6216 npm install gulp -E<\/code><\/pre>\n<p>\u8f93\u5165\u547d\u4ee4<strong>npm install gulp -ES\uff0c<\/strong>\u7559\u610fpackage.json \u6587\u4ef6\u7684 dependencies \u5b57\u6bb5\uff0c\u4ee5\u770b\u51fa\u7248\u672c\u53f7\u4e2d\u7684<strong>^<\/strong>\u6d88\u5931\u4e86<\/p>\n<pre><code>&quot;dependencies&quot;: {\n    &quot;gulp&quot;: &quot;3.9.1&quot;\n}<\/code><\/pre>\n<p>\u6a21\u5757\u7684\u4f9d\u8d56\u90fd\u88ab\u5199\u5165\u4e86package.json\u6587\u4ef6\u540e\uff0c\u4ed6\u4eba\u6253\u5f00\u9879\u76ee\u7684\u6839\u76ee\u5f55\uff08\u9879\u76ee\u5f00\u6e90\u3001\u5185\u90e8\u56e2\u961f\u5408\u4f5c\uff09\uff0c\u4f7f\u7528npm install\u547d\u4ee4\u53ef\u4ee5\u6839\u636edependencies\u914d\u7f6e\u5b89\u88c5\u6240\u6709\u7684\u4f9d\u8d56\u5305<\/p>\n<pre><code>npm install<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/278431-20160608180225886-1359105042.jpg\" alt=\"img\" \/><\/p>\n<p>\u672c\u5730\u5b89\u88c5\uff08local\uff09<\/p>\n<pre><code>npm install gulp<\/code><\/pre>\n<p>\u5168\u5c40\u5b89\u88c5\uff08global\uff09,\u4f7f\u7528 -g \u6216 --global<\/p>\n<pre><code>npm install gulp -g<\/code><\/pre>\n<h2>npm uninstall \u5378\u8f7d\u6a21\u5757<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code>npm uninstall [&lt;@scope&gt;\/]&lt;pkg&gt;[@&lt;version&gt;]... [-S|--save|-D|--save-dev|-O|--save-optional]\n\naliases: remove, rm, r, un, unlink<\/code><\/pre>\n<p>\u5982\u5378\u8f7d\u5f00\u53d1\u7248\u672c\u7684\u6a21\u5757<\/p>\n<pre><code>npm uninstall gulp --save-dev<\/code><\/pre>\n<h2>npm update \u66f4\u65b0\u6a21\u5757<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code>npm update [-g] [&lt;pkg&gt;...]<\/code><\/pre>\n<h2>npm outdated \u68c0\u67e5\u6a21\u5757\u662f\u5426\u5df2\u7ecf\u8fc7\u65f6<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code>npm outdated [[&lt;@scope&gt;\/]&lt;pkg&gt; ...]<\/code><\/pre>\n<p>\u6b64\u547d\u4ee4\u4f1a\u5217\u51fa\u6240\u6709\u5df2\u7ecf\u8fc7\u65f6\u7684\u5305\uff0c\u53ef\u4ee5\u53ca\u65f6\u8fdb\u884c\u5305\u7684\u66f4\u65b0<\/p>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/278431-20160608184648105-1925655942.jpg\" alt=\"img\" \/><\/p>\n<h2>npm ls \u67e5\u770b\u5b89\u88c5\u7684\u6a21\u5757<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code>npm ls [[&lt;@scope&gt;\/]&lt;pkg&gt; ...]\n\naliases: list, la, ll<\/code><\/pre>\n<p>\u67e5\u770b\u5168\u5c40\u5b89\u88c5\u7684\u6a21\u5757\u53ca\u4f9d\u8d56 <\/p>\n<pre><code>npm ls -g <\/code><\/pre>\n<h2>npm init \u5728\u9879\u76ee\u4e2d\u5f15\u5bfc\u521b\u5efa\u4e00\u4e2apackage.json\u6587\u4ef6<\/h2>\n<p>\u5b89\u88c5\u5305\u7684\u4fe1\u606f\u53ef\u4fdd\u6301\u5230\u9879\u76ee\u7684package.json\u6587\u4ef6\u4e2d\uff0c\u4ee5\u4fbf\u540e\u7eed\u7684\u5176\u5b83\u7684\u9879\u76ee\u5f00\u53d1\u6216\u8005\u4ed6\u4eba\u5408\u4f5c\u4f7f\u7528\uff0c\u4e5f\u8bf4package.json\u5728\u9879\u76ee\u4e2d\u662f\u5fc5\u4e0d\u53ef\u5c11\u7684\u3002<\/p>\n<pre><code>npm init [-f|--force|-y|--yes]<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/278431-20160612103551324-1085207978.gif\" alt=\"img\" \/><\/p>\n<h2>npm help \u67e5\u770b\u67d0\u6761\u547d\u4ee4\u7684\u8be6\u7ec6\u5e2e\u52a9<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code>npm help &lt;term&gt; [&lt;terms..&gt;]<\/code><\/pre>\n<p>\u4f8b\u5982\u8f93\u5165<code>npm help install\uff0c\u7cfb\u7edf\u5728\u9ed8\u8ba4\u7684\u6d4f\u89c8\u5668\u6216\u8005\u9ed8\u8ba4\u7684\u7f16\u8f91\u5668\u4e2d\u6253\u5f00\u672c\u5730nodejs\u5b89\u88c5\u5305\u7684\u6587\u4ef6\/nodejs\/node_modules\/npm\/html\/doc\/cli\/npm-install.html<\/code><\/p>\n<pre><code>npm help install<\/code><\/pre>\n<h2><strong>npm root<\/strong> \u67e5\u770b\u5305\u7684\u5b89\u88c5\u8def\u5f84<\/h2>\n<p>\u8f93\u51fa node_modules\u7684\u8def\u5f84<\/p>\n<pre><code>npm root [-g]<\/code><\/pre>\n<h2><strong>npm config<\/strong> \u7ba1\u7406npm\u7684\u914d\u7f6e\u8def\u5f84<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code>npm config set &lt;key&gt; &lt;value&gt; [-g|--global]\nnpm config get &lt;key&gt;\nnpm config delete &lt;key&gt;\nnpm config list\nnpm config edit\nnpm get &lt;key&gt;\nnpm set &lt;key&gt; &lt;value&gt; [-g|--global]<\/code><\/pre>\n<p>\u5bf9\u4e8econfig\u8fd9\u5757\u7528\u5f97\u6700\u591a\u5e94\u8be5\u662f<strong>\u8bbe\u7f6e\u4ee3\u7406\uff0c\u89e3\u51b3npm\u5b89\u88c5\u4e00\u4e9b\u6a21\u5757\u5931\u8d25\u7684\u95ee\u9898<\/strong><\/p>\n<p>\u4f8b\u5982\u6211\u5728\u516c\u53f8\u5185\u7f51\uff0c\u56e0\u4e3a\u516c\u53f8\u7684\u9632\u706b\u5899\u539f\u56e0\uff0c\u65e0\u6cd5\u5b8c\u6210\u4efb\u4f55\u6a21\u5757\u7684\u5b89\u88c5\uff0c\u8fd9\u4e2a\u65f6\u5019\u8bbe\u7f6e\u4ee3\u7406\u53ef\u4ee5\u89e3\u51b3<\/p>\n<pre><code>npm config set proxy=http:\/\/xxx.com:8080<\/code><\/pre>\n<p>\u53c8\u5982\u56fd\u5185\u7684\u7f51\u7edc\u73af\u5883\u95ee\u9898\uff0c\u67d0\u5b98\u65b9\u7684IP\u53ef\u80fd\u88ab\u548c\u8c10\u4e86\uff0c\u5e78\u597d\u56fd\u5185\u6709\u597d\u5fc3\u4eba\uff0c\u642d\u5efa\u4e86\u955c\u50cf\uff0c\u6b64\u65f6\u6211\u4eec\u7b80\u5355\u8bbe\u7f6e\u955c\u50cf<\/p>\n<pre><code>npm config set registry=&quot;http:\/\/r.cnpmjs.org&quot;<\/code><\/pre>\n<p>\u4e5f\u53ef\u4ee5\u4e34\u65f6\u914d\u7f6e\uff0c\u5982\u5b89\u88c5\u6dd8\u5b9d\u955c\u50cf<\/p>\n<pre><code>npm install -g cnpm --registry=https:\/\/registry.npm.taobao.org<\/code><\/pre>\n<h2>npm cache \u7ba1\u7406\u6a21\u5757\u7684\u7f13\u5b58<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code>npm cache add &lt;tarball file&gt;\nnpm cache add &lt;folder&gt;\nnpm cache add &lt;tarball url&gt;\nnpm cache add &lt;name&gt;@&lt;version&gt;\n\nnpm cache ls [&lt;path&gt;]\n\nnpm cache clean [&lt;path&gt;]<\/code><\/pre>\n<p>\u6700\u5e38\u7528\u547d\u4ee4\u65e0\u975e\u6e05\u9664npm\u672c\u5730\u7f13\u5b58<\/p>\n<pre><code>npm cache clean<\/code><\/pre>\n<h2>npm start \u542f\u52a8\u6a21\u5757<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code>npm start [-- &lt;args&gt;]<\/code><\/pre>\n<p>\u8be5\u547d\u4ee4\u5199\u5728package.json\u6587\u4ef6scripts\u7684start\u5b57\u6bb5\u4e2d\uff0c\u53ef\u4ee5\u81ea\u5b9a\u4e49\u547d\u4ee4\u6765\u914d\u7f6e\u4e00\u4e2a\u670d\u52a1\u5668\u73af\u5883\u548c\u5b89\u88c5\u4e00\u7cfb\u5217\u7684\u5fc5\u8981\u7a0b\u5e8f\uff0c\u5982<\/p>\n<pre><code>&quot;scripts&quot;: {\n    &quot;start&quot;: &quot;gulp -ws&quot;\n}<\/code><\/pre>\n<p>\u6b64\u65f6\u5728cmd\u4e2d\u8f93\u5165npm start\u547d\u4ee4\u76f8\u5f53\u4e8e\u6267\u884cgulpfile.js\u6587\u4ef6\u81ea\u5b9a\u4e49\u7684watch\u548cserver\u547d\u4ee4\u3002<\/p>\n<p>\u5982\u679cpackage.json\u6587\u4ef6\u6ca1\u6709\u8bbe\u7f6estart\uff0c\u5219\u5c06\u76f4\u63a5\u542f\u52a8node server.js<\/p>\n<h2>npm stop \u505c\u6b62\u6a21\u5757<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code>npm stop [-- &lt;args&gt;]<\/code><\/pre>\n<h2>npm restart \u91cd\u65b0\u542f\u52a8\u6a21\u5757<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code>npm restart [-- &lt;args&gt;]<\/code><\/pre>\n<h2>npm test \u6d4b\u8bd5\u6a21\u5757<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code>npm test [-- &lt;args&gt;]\nnpm tst [-- &lt;args&gt;]<\/code><\/pre>\n<p>\u8be5\u547d\u4ee4\u5199\u5728package.json\u6587\u4ef6scripts\u7684test\u5b57\u6bb5\u4e2d\uff0c\u53ef\u4ee5\u81ea\u5b9a\u4e49\u8be5\u547d\u4ee4\u6765\u6267\u884c\u4e00\u4e9b\u64cd\u4f5c\uff0c\u5982<\/p>\n<pre><code>&quot;scripts&quot;: {\n    &quot;test&quot;: &quot;gulp release&quot;\n},<\/code><\/pre>\n<p>\u6b64\u65f6\u5728cmd\u4e2d\u8f93\u5165npm test\u547d\u4ee4\u76f8\u5f53\u4e8e\u6267\u884cgulpfile.js\u6587\u4ef6\u81ea\u5b9a\u4e49\u7684release\u547d\u4ee4\u3002<\/p>\n<h2>npm version \u67e5\u770b\u6a21\u5757\u7248\u672c<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code>npm version [&lt;newversion&gt; | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git]\n\n&#039;npm [-v | --version]&#039; to print npm version\n&#039;npm view &lt;pkg&gt; version&#039; to view a package&#039;s published version\n&#039;npm ls&#039; to inspect current package\/dependency versions<\/code><\/pre>\n<p>\u67e5\u770b\u6a21\u5757\u7684\u7248\u672c<\/p>\n<pre><code>npm version<\/code><\/pre>\n<p><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/278431-20160612110731949-822739413.png\" alt=\"img\" \/><\/p>\n<h2>npm view \u67e5\u770b\u6a21\u5757\u7684\u6ce8\u518c\u4fe1\u606f<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code>npm view [&lt;@scope&gt;\/]&lt;name&gt;[@&lt;version&gt;] [&lt;field&gt;[.&lt;subfield&gt;]...]\n\naliases: info, show, v<\/code><\/pre>\n<p>\u67e5\u770b\u6a21\u5757\u7684\u4f9d\u8d56\u5173\u7cfb<\/p>\n<pre><code>npm view gulp dependencies<\/code><\/pre>\n<p>\u67e5\u770b\u6a21\u5757\u7684\u6e90\u6587\u4ef6\u5730\u5740<\/p>\n<pre><code>npm view gulp repository.url<\/code><\/pre>\n<p>\u67e5\u770b\u6a21\u5757\u7684\u8d21\u732e\u8005\uff0c\u5305\u542b\u90ae\u7bb1\u5730\u5740<\/p>\n<pre><code>npm view npm contributors<\/code><\/pre>\n<h2>npm adduser \u7528\u6237\u767b\u5f55<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code>npm adduser [--registry=url] [--scope=@orgname] [--always-auth]<\/code><\/pre>\n<h2><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/278431-20170117152013911-489932696.png\" alt=\"img\" \/><\/h2>\n<p>\u53d1\u5e03\u6a21\u677f\u5230npm\u793e\u533a\u524d\u9700\u8981\u5148\u767b\u5f55\uff0c\u7136\u540e\u518d\u8fdb\u5165\u53d1\u5e03\u7684\u64cd\u4f5c<\/p>\n<h2>npm publish \u53d1\u5e03\u6a21\u5757<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code>npm publish [&lt;tarball&gt;|&lt;folder&gt;] [--tag &lt;tag&gt;] [--access &lt;public|restricted&gt;]\n\nPublishes &#039;.&#039; if no argument supplied\nSets tag &#039;latest&#039; if no --tag specified<\/code><\/pre>\n<h2><img src=\"https:\/\/lemon-guess.oss-cn-hangzhou.aliyuncs.com\/img\/278431-20170117152224005-1557216239.png\" alt=\"img\" \/><\/h2>\n<h2>npm access \u5728\u53d1\u5e03\u7684\u5305\u4e0a\u8bbe\u7f6e\u8bbf\u95ee\u7ea7\u522b<\/h2>\n<p>\u57fa\u7840\u8bed\u6cd5<\/p>\n<pre><code>npm access public [&lt;package&gt;]\nnpm access restricted [&lt;package&gt;]\n\nnpm access grant &lt;read-only|read-write&gt; &lt;scope:team&gt; [&lt;package&gt;]\nnpm access revoke &lt;scope:team&gt; [&lt;package&gt;]\n\nnpm access ls-packages [&lt;user&gt;|&lt;scope&gt;|&lt;scope:team&gt;]\nnpm access ls-collaborators [&lt;package&gt; [&lt;user&gt;]]\nnpm access edit [&lt;package&gt;]<\/code><\/pre>\n<h2>npm package.json\u7684\u8bed\u6cd5<\/h2>\n<p>\u82f1\u6587\u539f\u7248\uff1a<a href=\"https:\/\/docs.npmjs.com\/files\/package.json\">https:\/\/docs.npmjs.com\/files\/package.json<\/a><\/p>\n<p>\u8fd9\u5757\u5185\u5bb9\u597d\u591a\uff0c\u56fd\u5185\u6709\u597d\u5fc3\u4eba\u6574\u7406\uff1a\u300a<a href=\"https:\/\/github.com\/ericdum\/mujiang.info\/issues\/6\/\">npm\u7684package.json\u4e2d\u6587\u6587\u6863<\/a>\u300b\uff0c\u4ece\u8fd9\u4efd\u6587\u6863\u62f7\u8d1d\u51fa\u4e00\u4e9b\u6bd4\u8f83\u5e38\u89c1\u7684\uff0c\u5982\u4e0b\uff1a<\/p>\n<p><strong>\u9ed8\u8ba4\u503c<\/strong><\/p>\n<p>npm\u4f1a\u6839\u636e\u5305\u5185\u5bb9\u8bbe\u7f6e\u4e00\u4e9b\u9ed8\u8ba4\u503c\u3002<\/p>\n<ul>\n<li>\n<p><code>&quot;scripts&quot;: {&quot;start&quot;: &quot;node server.js&quot;}<\/code><\/p>\n<p>\u5982\u679c\u5305\u7684\u6839\u76ee\u5f55\u6709<code>server.js<\/code>\u6587\u4ef6\uff0cnpm\u4f1a\u9ed8\u8ba4\u5c06<code>start<\/code>\u547d\u4ee4\u8bbe\u7f6e\u4e3a<code>node server.js<\/code>\u3002<\/p>\n<\/li>\n<li>\n<p><code>&quot;scripts&quot;:{&quot;preinstall&quot;: &quot;node-waf clean || true; node-waf configure build&quot;}<\/code><\/p>\n<p>\u5982\u679c\u5305\u7684\u6839\u76ee\u5f55\u6709<code>wscript<\/code>\u6587\u4ef6\uff0cnpm\u4f1a\u9ed8\u8ba4\u5c06<code>preinstall<\/code>\u547d\u4ee4\u7528node-waf\u8fdb\u884c\u7f16\u8bd1\u3002<\/p>\n<\/li>\n<li>\n<p><code>&quot;scripts&quot;:{&quot;preinstall&quot;: &quot;node-gyp rebuild&quot;}<\/code><\/p>\n<p>\u5982\u679c\u5305\u7684\u6839\u76ee\u5f55\u6709<code>binding.gyp<\/code>\u6587\u4ef6\uff0cnpm\u4f1a\u9ed8\u8ba4\u5c06<code>preinstall<\/code>\u547d\u4ee4\u7528node-gyp\u8fdb\u884c\u7f16\u8bd1\u3002<\/p>\n<\/li>\n<li>\n<p><code>&quot;contributors&quot;: [...]<\/code><\/p>\n<p>\u5982\u679c\u5305\u7684\u6839\u76ee\u5f55\u6709<code>AUTHORS<\/code>\u6587\u4ef6\uff0cnpm\u4f1a\u9ed8\u8ba4\u9010\u884c\u6309<code>Name &lt;email&gt; (url)<\/code>\u683c\u5f0f\u5904\u7406\uff0c\u90ae\u7bb1\u548curl\u662f\u53ef\u9009\u7684\u3002#\u53f7\u548c\u7a7a\u683c\u5f00\u5934\u7684\u884c\u4f1a\u88ab\u5ffd\u7565\u3002<\/p>\n<\/li>\n<\/ul>\n<p><strong>name<\/strong><\/p>\n<p>\u5728package.json\u4e2d\u6700\u91cd\u8981\u7684\u5c31\u662fname\u548cversion\u5b57\u6bb5\u3002\u4ed6\u4eec\u90fd\u662f\u5fc5\u987b\u7684\uff0c\u5982\u679c\u6ca1\u6709\u5c31\u65e0\u6cd5install\u3002name\u548cversion\u4e00\u8d77\u7ec4\u6210\u7684\u6807\u8bc6\u5728\u5047\u8bbe\u4e2d\u662f\u552f\u4e00\u7684\u3002\u6539\u53d8\u5305\u5e94\u8be5\u540c\u65f6\u6539\u53d8version\u3002<\/p>\n<p>name\u662f\u8fd9\u4e2a\u4e1c\u897f\u7684\u540d\u5b57\u3002\u6ce8\u610f\uff1a<\/p>\n<ul>\n<li>\u4e0d\u8981\u628anode\u6216\u8005js\u653e\u5728\u540d\u5b57\u4e2d\u3002\u56e0\u4e3a\u4f60\u5199\u4e86package.json\u5b83\u5c31\u88ab\u5047\u5b9a\u6210\u4e3a\u4e86js\uff0c\u4e0d\u8fc7\u4f60\u53ef\u4ee5\u7528&quot;engine&quot;\u5b57\u6bb5\u6307\u5b9a\u4e00\u4e2a\u5f15\u64ce\uff08\u89c1\u540e\u6587\uff09\u3002<\/li>\n<li>\u8fd9\u4e2a\u540d\u5b57\u4f1a\u4f5c\u4e3a\u5728URL\u7684\u4e00\u90e8\u5206\u3001\u547d\u4ee4\u884c\u7684\u53c2\u6570\u6216\u8005\u6587\u4ef6\u5939\u7684\u540d\u5b57\u3002\u4efb\u4f55non-url-safe\u7684\u5b57\u7b26\u90fd\u662f\u4e0d\u80fd\u7528\u7684\u3002<\/li>\n<li>\u8fd9\u4e2a\u540d\u5b57\u53ef\u80fd\u4f1a\u4f5c\u4e3a\u53c2\u6570\u88ab\u4f20\u5165require()\uff0c\u6240\u4ee5\u5b83\u5e94\u8be5\u6bd4\u8f83\u77ed\uff0c\u4f46\u4e5f\u8981\u610f\u4e49\u6e05\u6670\u3002<\/li>\n<li>\u5728\u4f60\u7231\u4e0a\u4f60\u7684\u540d\u5b57\u4e4b\u524d\uff0c\u4f60\u53ef\u80fd\u8981\u53bbnpm registry\u67e5\u770b\u4e00\u4e0b\u8fd9\u4e2a\u540d\u5b57\u662f\u5426\u5df2\u7ecf\u88ab\u4f7f\u7528\u4e86\u3002<a href=\"http:\/\/registry.npmjs.org\/\">http:\/\/registry.npmjs.org\/<\/a><\/li>\n<\/ul>\n<p><strong>version<\/strong><\/p>\n<p>version\u5fc5\u987b\u80fd\u88ab<a href=\"https:\/\/github.com\/isaacs\/node-semver\">node-semver<\/a>\u89e3\u6790\uff0c\u5b83\u88ab\u5305\u5728npm\u7684\u4f9d\u8d56\u4e2d\u3002\uff08\u8981\u81ea\u5df1\u7528\u53ef\u4ee5\u6267\u884c<code>npm install semver<\/code>\uff09<\/p>\n<p>\u53ef\u7528\u7684\u201c\u6570\u5b57\u201d\u6216\u8005\u201c\u8303\u56f4\u201d\u89c1<a href=\"https:\/\/npmjs.org\/doc\/misc\/semver.html\">semver(7)<\/a>.<\/p>\n<p><strong>description<\/strong><\/p>\n<p>\u653e\u7b80\u4ecb\uff0c\u5b57\u7b26\u4e32\uff0c\u65b9\u4fbf\u5728<code>npm search<\/code>\u4e2d\u641c\u7d22<\/p>\n<p><strong>keywords<\/strong><\/p>\n<p>\u5173\u952e\u5b57\uff0c\u6570\u7ec4\u3001\u5b57\u7b26\u4e32\uff0c\u65b9\u4fbf\u5728<code>npm search<\/code>\u4e2d\u641c\u7d22<\/p>\n<p><strong>bugs<\/strong><\/p>\n<p>\u4f60\u9879\u76ee\u7684\u63d0\u4ea4\u95ee\u9898\u7684url\u548c\uff08\u6216\uff09\u90ae\u4ef6\u5730\u5740<\/p>\n<pre><code>{\n &quot;url&quot; : &quot;http:\/\/github.com\/owner\/project\/issues&quot;, \n&quot;email&quot; : &quot;project@hostname.com&quot;\n}<\/code><\/pre>\n<p><strong>license<\/strong><\/p>\n<p>\u4f60\u5e94\u8be5\u8981\u6307\u5b9a\u4e00\u4e2a\u8bb8\u53ef\u8bc1\uff0c\u8ba9\u4eba\u77e5\u9053\u4f7f\u7528\u7684\u6743\u5229\u548c\u9650\u5236\u7684\u3002<\/p>\n<p>\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\uff0c\u5047\u5982\u4f60\u7528\u4e00\u4e2a\u50cfBSD\u6216\u8005MIT\u8fd9\u6837\u901a\u7528\u7684\u8bb8\u53ef\u8bc1\uff0c\u5c31\u53ea\u9700\u8981\u6307\u5b9a\u4e00\u4e2a\u8bb8\u53ef\u8bc1\u7684\u540d\u5b57\uff0c\u50cf\u8fd9\u6837\uff1a<\/p>\n<pre><code>{ &quot;license&quot; : &quot;BSD&quot; }<\/code><\/pre>\n<p>\u5982\u679c\u4f60\u53c8\u66f4\u590d\u6742\u7684\u8bb8\u53ef\u6761\u4ef6\uff0c\u6216\u8005\u60f3\u8981\u63d0\u4f9b\u7ed9\u66f4\u591a\u5730\u7ec6\u8282\uff0c\u53ef\u4ee5\u8fd9\u6837:<\/p>\n<pre><code>&quot;licenses&quot; : [\n  { &quot;type&quot; : &quot;MyLicense&quot;\n  , &quot;url&quot; : &quot;http:\/\/github.com\/owner\/project\/path\/to\/license&quot;\n  }\n]<\/code><\/pre>\n<p><strong>repository<\/strong><\/p>\n<p>\u6307\u5b9a\u4f60\u7684\u4ee3\u7801\u5b58\u653e\u7684\u5730\u65b9\u3002\u8fd9\u4e2a\u5bf9\u5e0c\u671b\u8d21\u732e\u7684\u4eba\u6709\u5e2e\u52a9\u3002\u5982\u679cgit\u4ed3\u5e93\u5728github\u4e0a\uff0c\u90a3\u4e48<code>npm docs<\/code>\u547d\u4ee4\u80fd\u627e\u5230\u4f60\u3002<\/p>\n<p>\u8fd9\u6837\u505a\uff1a<\/p>\n<pre><code>&quot;repository&quot; :\n  { &quot;type&quot; : &quot;git&quot;\n  , &quot;url&quot; : &quot;http:\/\/github.com\/isaacs\/npm.git&quot;\n  }\n\n&quot;repository&quot; :\n  { &quot;type&quot; : &quot;svn&quot;\n  , &quot;url&quot; : &quot;http:\/\/v8.googlecode.com\/svn\/trunk\/&quot;\n  }<\/code><\/pre>\n<p>URL\u5e94\u8be5\u662f\u516c\u5f00\u7684\uff08\u5373\u4fbf\u662f\u53ea\u8bfb\u7684\uff09\u80fd\u76f4\u63a5\u88ab\u672a\u7ecf\u8fc7\u4fee\u6539\u7684\u7248\u672c\u63a7\u5236\u7a0b\u5e8f\u5904\u7406\u7684url\u3002\u4e0d\u5e94\u8be5\u662f\u4e00\u4e2ahtml\u7684\u9879\u76ee\u9875\u9762\u3002\u56e0\u4e3a\u5b83\u662f\u7ed9\u8ba1\u7b97\u673a\u770b\u7684\u3002<\/p>\n<p><strong>scripts<\/strong><\/p>\n<p>\u201cscripts\u201d\u662f\u4e00\u4e2a\u7531\u811a\u672c\u547d\u4ee4\u7ec4\u6210\u7684hash\u5bf9\u8c61\uff0c\u4ed6\u4eec\u5728\u5305\u4e0d\u540c\u7684\u751f\u547d\u5468\u671f\u4e2d\u88ab\u6267\u884c\u3002key\u662f\u751f\u547d\u5468\u671f\u4e8b\u4ef6\uff0cvalue\u662f\u8981\u8fd0\u884c\u7684\u547d\u4ee4\u3002<\/p>\n<p>\u53c2\u8003\u4e0a\u9762\u7684<a href=\"https:\/\/www.cnblogs.com\/PeunZhang\/p\/5553574.html#npm-start\">npm start<\/a>\u3001<a href=\"https:\/\/www.cnblogs.com\/PeunZhang\/p\/5553574.html#npm-test\">npm test<\/a>\u547d\u4ee4<\/p>\n<p>\u66f4\u591a\u8be6\u7ec6\u8bf7\u770b <a href=\"https:\/\/npmjs.org\/doc\/misc\/npm-scripts.html\">npm-scripts(7)<\/a><\/p>\n<p><strong>config<\/strong><\/p>\n<p>&quot;config&quot; hash\u53ef\u4ee5\u7528\u6765\u914d\u7f6e\u7528\u4e8e\u5305\u811a\u672c\u4e2d\u7684\u8de8\u7248\u672c\u53c2\u6570\u3002\u5728\u5b9e\u4f8b\u4e2d\uff0c\u5982\u679c\u4e00\u4e2a\u5305\u6709\u4e0b\u9762\u7684\u914d\u7f6e\uff1a<\/p>\n<pre><code>{\n &quot;name&quot; : &quot;foo&quot;,\n &quot;config&quot; : { &quot;port&quot; : &quot;8080&quot; } \n}<\/code><\/pre>\n<p>\u7136\u540e\u6709\u4e00\u4e2a\u201cstart\u201d\u547d\u4ee4\u5f15\u7528\u4e86<code>npm_package_config_port<\/code>\u73af\u5883\u53d8\u91cf\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7<code>npm config set foo:port 8001<\/code>\u6765\u91cd\u5199\u4ed6\u3002<\/p>\n<p>\u53c2\u89c1 <a href=\"https:\/\/npmjs.org\/doc\/misc\/npm-config.html\">npm-config(7)<\/a> \u548c <a href=\"https:\/\/npmjs.org\/doc\/misc\/npm-scripts.html\">npm-scripts(7)<\/a>\u3002<\/p>\n<p><strong>dependencies<\/strong><\/p>\n<p>\u4f9d\u8d56\u662f\u7ed9\u4e00\u7ec4\u5305\u540d\u6307\u5b9a\u7248\u672c\u8303\u56f4\u7684\u4e00\u4e2ahash\u3002\u8fd9\u4e2a\u7248\u672c\u8303\u56f4\u662f\u4e00\u4e2a\u7531\u4e00\u4e2a\u6216\u591a\u4e2a\u7a7a\u683c\u5206\u9694\u7684\u5b57\u7b26\u4e32\u3002\u4f9d\u8d56\u8fd8\u53ef\u4ee5\u7528tarball\u6216\u8005git URL\u3002<\/p>\n<p>\u8bf7\u4e0d\u8981\u5c06\u6d4b\u8bd5\u6216\u8fc7\u6e21\u6027\u7684\u4f9d\u8d56\u653e\u5728<code>dependencies<\/code>hash\u4e2d\u3002\u89c1\u4e0b\u6587\u7684<code>devDependencies<\/code><\/p>\n<p><strong>\u8be6\u89c1<a href=\"https:\/\/npmjs.org\/doc\/misc\/semver.html\">semver(7)<\/a>.<\/strong><\/p>\n<ul>\n<li><code>version<\/code> \u5fc5\u987b\u5b8c\u5168\u548c<code>version<\/code>\u4e00\u81f4<\/li>\n<li><code>&gt;version<\/code> \u5fc5\u987b\u6bd4<code>version<\/code>\u5927<\/li>\n<li><code>&gt;=version<\/code> \u540c\u4e0a<\/li>\n<li><code>&lt;version<\/code> \u540c\u4e0a<\/li>\n<li><code>&lt;=version<\/code> \u540c\u4e0a<\/li>\n<li><code>~version<\/code> \u5927\u7ea6\u4e00\u6837\uff0c\u89c1<a href=\"https:\/\/npmjs.org\/doc\/misc\/semver.html\">semver(7)<\/a><\/li>\n<li><code>1.2.x<\/code> 1.2.0, 1.2.1, \u7b49\uff0c\u4f46\u4e0d\u5305\u62ec1.3.0<\/li>\n<li><code>http:\/\/...<\/code> \u89c1\u4e0b\u6587'\u4f9d\u8d56URL'<\/li>\n<li><code>*<\/code> \u6240\u6709<\/li>\n<li><code>&quot;&quot;<\/code> \u7a7a\uff0c\u540c<code>*<\/code><\/li>\n<li><code>version1 - version2<\/code> \u540c <code>&gt;=version1 &lt;=version2<\/code>.<\/li>\n<li><code>range1 || range2<\/code> \u4e8c\u9009\u4e00\u3002<\/li>\n<li><code>git...<\/code> \u89c1\u4e0b\u6587'\u4f9d\u8d56Git URL'<\/li>\n<li><code>user\/repo<\/code> \u89c1\u4e0b\u6587'GitHub URLs'<\/li>\n<\/ul>\n<p>\u6bd4\u5982\u4e0b\u9762\u90fd\u662f\u5408\u6cd5\u7684\uff1a<\/p>\n<pre><code>{ &quot;dependencies&quot; :\n  { &quot;foo&quot; : &quot;1.0.0 - 2.9999.9999&quot;\n  , &quot;bar&quot; : &quot;&gt;=1.0.2 &lt;2.1.2&quot;\n  , &quot;baz&quot; : &quot;&gt;1.0.2 &lt;=2.3.4&quot;\n  , &quot;boo&quot; : &quot;2.0.1&quot;\n  , &quot;qux&quot; : &quot;&lt;1.0.0 || &gt;=2.3.1 &lt;2.4.5 || &gt;=2.5.2 &lt;3.0.0&quot;\n  , &quot;asd&quot; : &quot;http:\/\/asdf.com\/asdf.tar.gz&quot;\n  , &quot;til&quot; : &quot;~1.2&quot;\n  , &quot;elf&quot; : &quot;~1.2.3&quot;\n  , &quot;two&quot; : &quot;2.x&quot;\n  , &quot;thr&quot; : &quot;3.3.x&quot;\n  }\n}<\/code><\/pre>\n<p><strong>devDependencies<\/strong><\/p>\n<p>\u5982\u679c\u6709\u4eba\u8981\u4f7f\u7528\u4f60\u7684\u6a21\u5757\uff0c\u90a3\u4e48\u4ed6\u4eec\u53ef\u80fd\u4e0d\u9700\u8981\u4f60\u5f00\u53d1\u4f7f\u7528\u7684\u5916\u90e8\u6d4b\u8bd5\u6216\u8005\u6587\u6863\u6846\u67b6\u3002<\/p>\n<p>\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6700\u597d\u5c06\u8fd9\u4e9b\u9644\u5c5e\u7684\u9879\u76ee\u5217\u5728<code>devDependencies<\/code>\u4e2d\u3002<\/p>\n<p>\u8fd9\u4e9b\u4e1c\u897f\u4f1a\u5728\u6267\u884c<code>npm link<\/code>\u6216\u8005<code>npm install<\/code>\u7684\u65f6\u5019\u521d\u59cb\u5316\uff0c\u5e76\u53ef\u4ee5\u50cf\u5176\u4ed6npm\u914d\u7f6e\u53c2\u6570\u4e00\u6837\u7ba1\u7406\u3002\u8be6\u89c1<a href=\"https:\/\/npmjs.org\/doc\/misc\/npm-config.html\">npm-config(7)<\/a>\u3002<\/p>\n<p>\u5bf9\u4e8e\u975e\u7279\u5b9a\u5e73\u53f0\u7684\u6784\u5efa\u6b65\u9aa4\uff0c\u6bd4\u5982\u9700\u8981\u7f16\u8bd1CoffeeScript\uff0c\u53ef\u4ee5\u7528<code>prepublish<\/code>\u811a\u672c\u53bb\u5b9e\u73b0\uff0c\u5e76\u628a\u5b83\u4f9d\u8d56\u7684\u5305\u653e\u5728devDependency\u4e2d\u3002\uff08\u8bd1\u8005\u6ce8\uff1aprepublish\u5b9a\u4e49\u4e86\u5728\u6267\u884c<code>npm publish<\/code>\u7684\u65f6\u5019\u5148\u884c\u6267\u884c\u7684\u811a\u672c\uff09<\/p>\n<p>\u6bd4\u5982\uff1a<\/p>\n<pre><code>{ &quot;name&quot;: &quot;ethopia-waza&quot;,\n  &quot;description&quot;: &quot;a delightfully fruity coffee varietal&quot;,\n  &quot;version&quot;: &quot;1.2.3&quot;,\n  &quot;devDependencies&quot;: {\n    &quot;coffee-script&quot;: &quot;~1.6.3&quot;\n  },\n  &quot;scripts&quot;: {\n    &quot;prepublish&quot;: &quot;coffee -o lib\/ -c src\/waza.coffee&quot;\n  },\n  &quot;main&quot;: &quot;lib\/waza.js&quot;\n}<\/code><\/pre>\n<p><code>prepublish<\/code>\u811a\u672c\u4f1a\u5728publishing\u524d\u8fd0\u884c\uff0c\u8fd9\u6837\u7528\u6237\u5c31\u4e0d\u7528\u81ea\u5df1\u53bbrequire\u6765\u7f16\u8bd1\u5c31\u80fd\u4f7f\u7528\u3002\u5e76\u4e14\u5728\u5f00\u53d1\u6a21\u5f0f\u4e2d\uff08\u6bd4\u5982\u672c\u5730\u8fd0\u884c<code>npm install<\/code>\uff09\u4f1a\u8fd0\u884c\u8fd9\u4e2a\u811a\u672c\u4ee5\u4fbf\u66f4\u597d\u5730\u6d4b\u8bd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>npm\u662f\u4ec0\u4e48 NPM\u7684\u5168\u79f0\u662fNode Package Manager\uff0c\u662f\u968f\u540cNodeJS\u4e00\u8d77\u5b89\u88c5\u7684\u5305\u7ba1\u7406\u548c\u5206\u53d1\u5de5\u5177\uff0c\u5b83\u5f88\u65b9\u4fbf\u8ba9JavaS   \u2026 &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0},"categories":[89],"tags":[78,196],"_links":{"self":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts\/8880"}],"collection":[{"href":"\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=8880"}],"version-history":[{"count":1,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/8880\/revisions"}],"predecessor-version":[{"id":8881,"href":"\/index.php?rest_route=\/wp\/v2\/posts\/8880\/revisions\/8881"}],"wp:attachment":[{"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=8880"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=8880"},{"taxonomy":"post_tag","embeddable":true,"href":"\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=8880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}