{"id":6449,"date":"2022-10-18T13:12:48","date_gmt":"2022-10-18T05:12:48","guid":{"rendered":"https:\/\/www.lilichao.com\/?p=6449"},"modified":"2022-11-05T23:06:51","modified_gmt":"2022-11-05T15:06:51","slug":"%e6%a8%a1%e5%9d%97%e5%8c%96","status":"publish","type":"post","link":"https:\/\/lilichao.com\/?p=6449","title":{"rendered":"\u6a21\u5757\u5316"},"content":{"rendered":"\n<p>\u968f\u7740\u5b66\u4e60\u7684\u6df1\u5165\uff0c\u4ee3\u7801\u6570\u91cf\u7684\u589e\u591a\u6211\u4eec\u6240\u7f16\u5199\u7684\u7a0b\u5e8f\u590d\u6742\u5ea6\u8d8a\u6765\u8d8a\u9ad8\u3002\u6b64\u65f6\u5982\u679c\u6211\u4eec\u4f9d\u7136\u5c06\u6240\u6709\u7684\u4ee3\u7801\u7f16\u5199\u5230\u540c\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c\u4ee3\u7801\u5c06\u53d8\u5f97\u975e\u5e38\u96be\u4ee5\u7ef4\u62a4\u3002\u6a21\u5757\u5316\u662f\u89e3\u51b3\u8fd9\u79cd\u95ee\u9898\u7684\u5173\u952e\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u6211\u4eec\u5148\u6765\u89e3\u51b3\u7b2c\u4e00\u4e2a\u95ee\u9898 \u2014\u2014 \u4ec0\u4e48\u662f\u6a21\u5757\uff1f\u6a21\u5757\u7b80\u5355\u7406\u89e3\u5176\u5b9e\u5c31\u662f\u4e00\u4e2a\u4ee3\u7801\u7247\u6bb5\uff0c\u672c\u6765\u5199\u5728\u4e00\u8d77\u7684JS\u4ee3\u7801\uff0c\u6211\u4eec\u6309\u7167\u4e0d\u540c\u7684\u529f\u80fd\u5c06\u5b83\u62c6\u5206\u4e3a\u4e00\u4e2a\u4e00\u4e2a\u5c0f\u7684\u4ee3\u7801\u7247\u6bb5\uff0c\u8fd9\u4e2a\u4ee3\u7801\u7247\u6bb5\u5c31\u662f\u4e00\u4e2a\u6a21\u5757\u3002\u7b80\u5355\u6765\u8bf4\uff0c\u5c31\u662f\u5316\u6574\u4e3a\u96f6\u3002<\/p>\n\n\n\n<p>\u63a5\u7740\u6211\u4eec\u6765\u4e00\u8d77\u770b\u770b\u6a21\u5757\u5316\u4f1a\u7ed9\u6211\u4eec\u5e26\u6765\u54ea\u4e9b\u597d\u5904\uff0c\u6a21\u5757\u5316\u540e\u4e0d\u518d\u662f\u6240\u6709\u4ee3\u7801\u5199\u5728\u4e00\u8d77\uff0c\u800c\u662f\u6309\u529f\u80fd\u505a\u4e86\u4e0d\u540c\u7684\u533a\u5206\uff0c\u5f53\u6211\u4eec\u7ef4\u62a4\u4ee3\u7801\u65f6\u53ef\u4ee5\u6bd4\u8f83\u5feb\u6377\u7684\u627e\u5230\u90a3\u4e9b\u8981\u4fee\u6539\u7684\u4ee3\u7801\u3002\u518d\u8005\uff0c\u6a21\u5757\u5316\u540e\uff0c\u4ee3\u7801\u88ab\u62c6\u5206\u540e\u66f4\u5bb9\u6613\u88ab\u590d\u7528\uff0c\u540c\u6837\u4e00\u4e2a\u6a21\u5757\u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u9879\u76ee\u4e2d\u4f7f\u7528\uff0c\u5927\u5927\u7684\u964d\u4f4e\u4e86\u6211\u4eec\u7684\u5f00\u53d1\u6210\u672c\u3002\u4e4b\u524d\u6211\u4eec\u5b66\u4e60\u7684jQuery\u4fbf\u53ef\u4ee5\u7406\u89e3\u4e3a\u662f\u4e00\u79cd\u6a21\u5757\u3002<\/p>\n\n\n\n<p>\u4f46\u662fjQuery\u8fd9\u79cd\u6a21\u5757\u5316\u7684\u65b9\u5f0f\u5b58\u5728\u6709\u8bb8\u591a\u7684\u4e0d\u8db3\u3002jQuery\u662f\u901a\u8fc7script\u6807\u7b7e\u5f15\u5165\u7684\u5f62\u5f0f\u6765\u5b8c\u6210\u6a21\u5757\u5316\u7684\uff0c\u5f15\u5165\u540e\u5b9e\u9645\u6548\u679c\u662f\u5411\u5168\u5c40\u4f5c\u7528\u57df\u4e2d\u6dfb\u52a0\u4e86\u4e00\u4e2a\u53d8\u91cf$\uff08\u6216jQuery\uff09\u8fd9\u6837\u5f88\u5bb9\u6613\u51fa\u73b0\u6a21\u5757\u95f4\u4e92\u76f8\u8986\u76d6\u7684\u60c5\u51b5\u3002\u5e76\u4e14\u5f53\u6211\u4eec\u4f7f\u7528\u4e86\u8f83\u591a\u7684\u6a21\u5757\u65f6\uff0c\u6709\u4e00\u4e9b\u6a21\u5757\u662f\u76f8\u4e92\u4f9d\u8d56\u7684\uff0c\u5fc5\u987b\u5148\u5f15\u5165\u67d0\u4e2a\u7ec4\u4ef6\u518d\u5f15\u5165\u67d0\u4e2a\u7ec4\u4ef6\uff0c\u6a21\u5757\u624d\u80fd\u591f\u6b63\u5e38\u5de5\u4f5c\u3002\u6bd4\u5982jQuery\u548cjQueryUI\uff0c\u5c31\u5fc5\u987b\u5148\u5f15\u5165jQuery\uff0c\u5982\u679c\u5f15\u5165\u987a\u5e8f\u51fa\u9519\u5c06\u5bfc\u81f4jQueryUI\u65e0\u6cd5\u4f7f\u7528\u3002\u8fd9\u8fd8\u4ec5\u4ec5\u662f\u4e24\u4e2a\u7ec4\u4ef6\uff0c\u800c\u5b9e\u9645\u5f00\u53d1\u4e2d\u7684\u4f9d\u8d56\u5173\u7cfb\u5f80\u5f80\u66f4\u52a0\u590d\u6742\uff0c\u50cf\u662fa\u4f9d\u8d56b\uff0cb\u4f9d\u8d56c\uff0cc\u4f9d\u8d56d\u8fd9\u79cd\u5173\u7cfb\uff0c\u5fc5\u987b\u6309\u7167d\u3001c\u3001b\u3001a\u7684\u987a\u5e8f\u8fdb\u884c\u5f15\u5165\uff0c\u6709\u4e00\u4e2a\u987a\u5e8f\u9519\u8bef\u5c31\u4f1a\u5bfc\u81f4\u5176\u4ed6\u7684\u4e00\u8d77\u5931\u6548\u3002\u6240\u4ee5\u901a\u8fc7script\u6807\u7b7e\u5b9e\u73b0\u7684\u6a21\u5757\u5316\u662f\u975e\u5e38\u7684\u4e0d\u9760\u8c31\u7684\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">CommonJS<\/h2>\n\n\n\n<p>\u4e00\u76f4\u52302015\u5e74\uff0cJavaScript\u4e2d\u4e00\u76f4\u90fd\u6ca1\u6709\u4e00\u4e2a\u5185\u7f6e\u7684\u6a21\u5757\u5316\u7cfb\u7edf\u3002\u4f46\u662f\u968f\u7740JavaScript\u9879\u76ee\u8d8a\u6765\u8d8a\u590d\u6742\uff0c\u6a21\u5757\u5316\u7684\u9700\u6c42\u65e9\u5df2\u8feb\u5728\u7709\u776b\u3002\u4e8e\u662f\u5927\u795e\u95e8\u5f00\u59cb\u7740\u624b\u81ea\u5b9a\u4e49\u4e00\u4e2a\u6a21\u5757\u5316\u7cfb\u7edf\uff0cCommonJS\u4fbf\u662f\u5176\u4e2d\u7684\u4f7c\u4f7c\u8005\u3002\u540c\u65f6\u5b83\u4e5f\u662fNode.js\u4e2d\u9ed8\u8ba4\u4f7f\u7528\u7684\u6a21\u5757\u5316\u6807\u51c6\u3002<\/p>\n\n\n\n<p>\u6a21\u5757\u5c31\u662f\u4e00\u4e2ajs\u6587\u4ef6\uff0c\u5728\u6a21\u5757\u5185\u90e8\u4efb\u4f55\u53d8\u91cf\u6216\u5176\u4ed6\u5bf9\u8c61\u90fd\u662f\u79c1\u6709\u7684\uff0c\u4e0d\u4f1a\u66b4\u9732\u7ed9\u5916\u90e8\u6a21\u5757\u3002\u5728CommonJS\u6a21\u5757\u5316\u89c4\u8303\u4e2d\uff0c\u5728\u6a21\u5757\u5185\u90e8\u5b9a\u4e49\u4e86\u4e00\u4e2amodule\u5bf9\u8c61\uff0cmodule\u5bf9\u8c61\u5185\u90e8\u5b58\u50a8\u4e86\u5f53\u524d\u6a21\u5757\u7684\u57fa\u672c\u4fe1\u606f\uff0c\u540c\u65f6module\u5bf9\u8c61\u4e2d\u6709\u4e00\u4e2a\u5c5e\u6027\u540d\u4e3aexports\uff0cexports\u7528\u6765\u6307\u5b9a\u9700\u8981\u5411\u5916\u90e8\u66b4\u9732\u7684\u5185\u5bb9\u3002\u53ea\u9700\u8981\u5c06\u9700\u8981\u66b4\u9732\u7684\u5185\u5bb9\u8bbe\u7f6e\u4e3aexports\u6216exports\u7684\u5c5e\u6027\uff0c\u5176\u4ed6\u6a21\u5757\u5373\u53ef\u901a\u8fc7require\u6765\u83b7\u53d6\u8fd9\u4e9b\u66b4\u9732\u7684\u5185\u5bb9\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>const a = 10\nconst b = 20\nconst obj = { name: &quot;\u5b59\u609f\u7a7a&quot; }\n\nmodule.exports = a\n\n\/\/ const a = require(&quot;.\/m.js&quot;)<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>const a = 10\nconst b = 20\nconst obj = { name: &quot;\u5b59\u609f\u7a7a&quot; }\n\nmodule.exports.a = a\nmodule.exports.b = b\n\n\/\/ const {a, b} = require(&quot;.\/m.js&quot;)<\/code><\/pre><\/div>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>const a = 10\nconst b = 20\nconst obj = { name: &quot;\u5b59\u609f\u7a7a&quot; }\n\nmodule.exports = {\n    a,\n    b,\n    obj\n}\n\n\/\/ const {a, b, obj} = require(&quot;.\/m.js&quot;)<\/code><\/pre><\/div>\n\n\n\n<p>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cNode.js\u4f1a\u5c06\u4ee5\u4e0b\u5185\u5bb9\u89c6\u4e3aCommonJS\u6a21\u5757\uff1a<\/p>\n\n\n\n<ol><li>\u4f7f\u7528.cjs\u4e3a\u6269\u5c55\u540d\u7684\u6587\u4ef6<\/li><li>\u5f53\u524d\u7684package.json\u7684type\u5c5e\u6027\u4e3acommonjs\u65f6\uff0c\u6269\u5c55\u540d\u4e3a.js\u7684\u6587\u4ef6<\/li><li>\u5f53\u524d\u7684package.json\u4e0d\u5305\u542btype\u5c5e\u6027\u65f6\uff0c\u6269\u5c55\u540d\u4e3a.js\u7684\u6587\u4ef6<\/li><li>\u6587\u4ef6\u7684\u6269\u5c55\u540d\u662fmjs\u3001cjs\u3001json\u3001node\u3001js\u4ee5\u5916\u7684\u503c\u65f6\uff08type\u4e0d\u662fmodule\u65f6\uff09<\/li><\/ol>\n\n\n\n<p>require()\u662f\u540c\u6b65\u52a0\u8f7d\u6a21\u5757\u7684\u65b9\u6cd5\uff0c\u6240\u4ee5\u65e0\u6cd5\u7528\u6765\u52a0\u8f7dES6\u7684\u6a21\u5757\u3002\u5f53\u6211\u4eec\u9700\u8981\u5728CommonJS\u4e2d\u52a0\u8f7dES\u6a21\u5757\u65f6\uff0c\u9700\u8981\u901a\u8fc7import()\u65b9\u6cd5\u6765\u52a0\u8f7d\u3002<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>import(&quot;.\/m2.mjs&quot;).then(m2 =&gt; {\n    console.log(m2)\n})<\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u6587\u4ef6\u4f5c\u4e3a\u6a21\u5757<\/h3>\n\n\n\n<p>\u5f53\u6211\u4eec\u52a0\u8f7d\u4e00\u4e2a\u81ea\u5b9a\u4e49\u7684\u6587\u4ef6\u6a21\u5757\u65f6\uff0c\u6a21\u5757\u7684\u8def\u5f84\u5fc5\u987b\u4ee5<code>\/\u3001.\/<\/code>\u6216<code>..\/<\/code>\u5f00\u5934\u3002\u5982\u679c\u4e0d\u4ee5\u8fd9\u4e9b\u5f00\u5934\uff0cnode\u4f1a\u8ba4\u4e3a\u4f60\u8981\u52a0\u8f7d\u7684\u662f\u6838\u5fc3\u6a21\u5757\u6216<code>node_modules<\/code>\u4e2d\u7684\u6a21\u5757\u3002<\/p>\n\n\n\n<p>\u5f53\u6211\u4eec\u8981\u52a0\u8f7d\u7684\u6a21\u5757\u662f\u4e00\u4e2a\u6587\u4ef6\u6a21\u5757\u65f6\uff0cCommonJS\u89c4\u8303\u4f1a\u5148\u53bb\u5bfb\u627e\u8be5\u6587\u4ef6\uff0c\u6bd4\u5982\uff1a<code>require(\".\/m1\")<\/code>\u65f6\uff0c\u4f1a\u9996\u5148\u5bfb\u627e\u540d\u4e3am1\u7684\u6587\u4ef6\u3002\u5982\u679c\u8fd9\u4e2a\u6587\u4ef6\u6ca1\u6709\u627e\u5230\uff0c\u5b83\u4f1a\u81ea\u52a8\u4e3a\u6587\u4ef6\u6dfb\u52a0\u6269\u5c55\u540d\u7136\u540e\u518d\u67e5\u8be2\u3002\u6269\u5c55\u540d\u7684\u987a\u5e8f\u4e3a\uff1ajs\u3001json\u548cnode\u3002\u8fd8\u662f\u4e0a\u8fb9\u7684\u4f8b\u5b50\uff0c\u5982\u679c\u6ca1\u6709\u627e\u5230m1\uff0c\u5219\u4f1a\u6309\u7167\u987a\u5e8f\u641c\u7d22m1.js\u3001m1.json\u3001m1.node\u54ea\u4e2a\u5148\u627e\u5230\u5219\u8fd4\u56de\u54ea\u4e2a\uff0c\u5982\u679c\u90fd\u6ca1\u6709\u627e\u5230\u5219\u62a5\u9519\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u6587\u4ef6\u5939\u4f5c\u4e3a\u6a21\u5757<\/h3>\n\n\n\n<p>\u5f53\u6211\u4eec\u4f7f\u7528\u4e00\u4e2a\u6587\u4ef6\u5939\u4f5c\u4e3a\u6a21\u5757\u65f6\uff0c\u6587\u4ef6\u5939\u4e2d\u5fc5\u987b\u6709\u4e00\u4e2a\u6a21\u5757\u7684\u4e3b\u6587\u4ef6\u3002\u5982\u679c\u6587\u4ef6\u5939\u4e2d\u542b\u6709<code>package.json<\/code>\u6587\u4ef6\u4e14\u6587\u4ef6\u4e2d\u8bbe\u7f6e<code>main<\/code>\u5c5e\u6027\uff0c\u5219<code>main<\/code>\u5c5e\u6027\u6307\u5b9a\u7684\u6587\u4ef6\u4f1a\u6210\u4e3a\u4e3b\u6587\u4ef6\uff0c\u5bfc\u5165\u6a21\u5757\u65f6\u5c31\u662f\u5bfc\u5165\u8be5\u6587\u4ef6\u3002\u5982\u679c\u6ca1\u6709<code>package.json<\/code>\uff0c\u5219node\u4f1a\u6309\u7167<code>index.js<\/code>\u3001<code>index.node<\/code>\u7684\u987a\u5e8f\u5bfb\u627e\u4e3b\u6587\u4ef6\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">node_modules<\/h3>\n\n\n\n<p>\u5982\u679c\u6211\u4eec\u52a0\u8f7d\u7684\u6a21\u5757\u6ca1\u6709\u4ee5<code>\/\u3001.\/<\/code>\u6216<code>..\/<\/code>\u5f00\u5934\uff0c\u4e14\u8981\u52a0\u8f7d\u7684\u6a21\u5757\u4e0d\u662f\u6838\u5fc3\u6a21\u5757\uff0cnode\u4f1a\u81ea\u52a8\u53bbnode_modules\u76ee\u5f55\u4e0b\u53bb\u52a0\u8f7d\u6a21\u5757\u3002node\u4f1a\u5148\u53bb\u5f53\u524d\u76ee\u5f55\u4e0b\u7684node_modules\u4e0b\u53bb\u5bfb\u627e\u6a21\u5757\uff0c\u627e\u5230\u5219\u4f7f\u7528\uff0c\u6ca1\u627e\u5230\u5219\u7ee7\u7eed\u53bb\u4e0a\u4e00\u5c42\u76ee\u5f55\u4e2d\u5bfb\u627e\uff0c\u4ee5\u6b64\u7c7b\u63a8\uff0c\u77e5\u9053\u627e\u5230\u6839\u76ee\u5f55\u4e0b\u7684node_modules\u4e3a\u6b62\u3002<\/p>\n\n\n\n<p>\u6bd4\u5982\uff0c\u5f53\u524d\u9879\u76ee\u7684\u76ee\u5f55\u4e3a\uff1a<code>'C:\\Users\\lilichao\\Desktop\\Node-Course\\myProject\\node_modules'<\/code>\uff0c\u5219\u6a21\u5757\u67e5\u627e\u987a\u5e8f\u4f9d\u6b21\u4e3a\uff1a<\/p>\n\n\n\n<p>&#8216;C:\\Users\\lilichao\\Desktop\\Node-Course\\node_modules&#8217;,<br>&#8216;C:\\Users\\lilichao\\Desktop\\node_modules&#8217;,<br>&#8216;C:\\Users\\lilichao\\node_modules&#8217;,<br>&#8216;C:\\Users\\node_modules&#8217;,<br>&#8216;C:\\node_modules&#8217;<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u6a21\u5757\u7684\u5305\u88c5<\/h3>\n\n\n\n<p>\u6bcf\u4e00\u4e2aCommonJS\u6a21\u5757\u5728\u6267\u884c\u65f6\uff0c\u5916\u5c42\u90fd\u4f1a\u88ab\u5957\u4e0a\u4e00\u4e2a\u51fd\u6570\uff1a<\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>(function(exports, require, module, __filename, __dirname) {\n\/\/ \u6a21\u5757\u4ee3\u7801\u4f1a\u88ab\u653e\u5230\u8fd9\u91cc\n});<\/code><\/pre><\/div>\n\n\n\n<p>\u6240\u4ee5\u6211\u4eec\u4e4b\u6240\u4ee5\u80fd\u5728CommonJS\u6a21\u5757\u4e2d\u4f7f\u7528<code>exports<\/code>\u3001<code>require<\/code>\u5e76\u4e0d\u662f\u56e0\u4e3a\u5b83\u4eec\u662f\u5168\u5c40\u53d8\u91cf\u3002\u5b83\u4eec\u5b9e\u9645\u4e0a\u4ee5\u53c2\u6570\u7684\u5f62\u5f0f\u4f20\u9012\u8fdb\u6a21\u5757\u7684\u3002<\/p>\n\n\n\n<p>exports\uff0c\u7528\u6765\u8bbe\u7f6e\u6a21\u5757\u5411\u5916\u90e8\u66b4\u9732\u7684\u5185\u5bb9<\/p>\n\n\n\n<p>require\uff0c\u7528\u6765\u5f15\u5165\u6a21\u5757\u7684\u65b9\u6cd5<\/p>\n\n\n\n<p>module\uff0c\u5f53\u524d\u6a21\u5757\u7684\u5f15\u7528<\/p>\n\n\n\n<p>__filename\uff0c\u6a21\u5757\u7684\u8def\u5f84<\/p>\n\n\n\n<p>__dirname\uff0c\u6a21\u5757\u6240\u5728\u76ee\u5f55\u7684\u8def\u5f84<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">ES\u6a21\u5757\u5316<\/h2>\n\n\n\n<p>2015\u5e74\u968f\u7740ES6\u6807\u51c6\u7684\u53d1\u5e03\uff0cES\u7684\u5185\u7f6e\u6a21\u5757\u5316\u7cfb\u7edf\u4e5f\u5e94\u8fd0\u800c\u751f\uff0c\u5e76\u4e14\u5728Node.js\u4e2d\u540c\u6837\u4e5f\u652f\u6301ES\u6807\u51c6\u7684\u6a21\u5757\u5316\u3002\u8bf4\u6765\u8bf4\u53bb\u4f7f\u7528\u6a21\u5757\u5316\u65e0\u975e\u9700\u8981\u6ce8\u610f\u4e24\u4ef6\u4e8b\u5bfc\u51fa\u548c\u5f15\u5165\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u5bfc\u51fa<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>\/\/ \u5bfc\u51fa\u53d8\u91cf\uff08\u547d\u540d\u5bfc\u51fa\uff09\nexport let name1, name2, \u2026, nameN; \nexport let name1 = \u2026, name2 = \u2026, \u2026, nameN; \n\u200b\n\/\/ \u5bfc\u51fa\u51fd\u6570\uff08\u547d\u540d\u5bfc\u51fa\uff09\nexport function functionName(){...}\n\u200b\n\/\/ \u5bfc\u51fa\u7c7b\uff08\u547d\u540d\u5bfc\u51fa\uff09\nexport class ClassName {...}\n\u200b\n\/\/ \u5bfc\u51fa\u4e00\u7ec4\nexport { name1, name2, \u2026, nameN };\n\u200b\n\/\/ \u91cd\u547d\u540d\u5bfc\u51fa\nexport { variable1 as name1, variable2 as name2, \u2026, nameN };\n\u200b\n\/\/ \u89e3\u6784\u8d4b\u503c\u540e\u5bfc\u51fa\nexport const { name1, name2: bar } = o;\n\u200b\n\/\/ \u9ed8\u8ba4\u5bfc\u51fa\nexport default expression;\nexport default function (\u2026) { \u2026 } \/\/ also class, function*\nexport default function name1(\u2026) { \u2026 } \/\/ also class, function*\nexport { name1 as default, \u2026 };\n\u200b\n\/\/ \u805a\u5408\u6a21\u5757\nexport * from \u2026; \/\/ \u5c06\u5176\u4ed6\u6a21\u5757\u4e2d\u7684\u5168\u90e8\u5185\u5bb9\u5bfc\u51fa\uff08\u9664\u4e86default\uff09\nexport * as name1 from \u2026; \/\/ ECMAScript\u00ae 2O20 \u5c06\u5176\u4ed6\u6a21\u5757\u4e2d\u7684\u5168\u90e8\u5185\u5bb9\u4ee5\u6307\u5b9a\u522b\u540d\u5bfc\u51fa\nexport { name1, name2, \u2026, nameN } from \u2026; \/\/ \u5c06\u5176\u4ed6\u6a21\u5757\u4e2d\u7684\u6307\u5b9a\u5185\u5bb9\u5bfc\u51fa\nexport { import1 as name1, import2 as name2, \u2026, nameN } from \u2026; \/\/ \u5c06\u5176\u4ed6\u6a21\u5757\u4e2d\u7684\u6307\u5b9a\u5185\u5bb9\u91cd\u547d\u540d\u5bfc\u51fa\nexport { default, \u2026 } from \u2026; <\/code><\/pre><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">\u5f15\u5165<\/h3>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-js\" data-lang=\"JavaScript\"><code>\/\/ \u5f15\u5165\u9ed8\u8ba4\u5bfc\u51fa\nimport defaultExport from &quot;module-name&quot;;\n\u200b\n\/\/ \u5c06\u6240\u6709\u6a21\u5757\u5bfc\u5165\u5230\u6307\u5b9a\u547d\u540d\u7a7a\u95f4\u4e2d\nimport * as name from &quot;module-name&quot;;\n\u200b\n\/\/ \u5f15\u5165\u6a21\u5757\u4e2d\u7684\u6307\u5b9a\u5185\u5bb9\nimport { export1 } from &quot;module-name&quot;;\nimport { export1 , export2 } from &quot;module-name&quot;;\n\u200b\n\/\/ \u4ee5\u6307\u5b9a\u522b\u540d\u5f15\u5165\u6a21\u5757\u4e2d\u7684\u6307\u5b9a\u5185\u5bb9\nimport { export1 as alias1 } from &quot;module-name&quot;;\nimport { export1 , export2 as alias2 , [...] } from &quot;module-name&quot;;\n\u200b\n\/\/ \u5f15\u5165\u9ed8\u8ba4\u548c\u5176\u4ed6\u5185\u5bb9\nimport defaultExport, { export1 [ , [...] ] } from &quot;module-name&quot;;\nimport defaultExport, * as name from &quot;module-name&quot;;\n\u200b\n\/\/ \u5f15\u5165\u6a21\u5757\nimport &quot;module-name&quot;;<\/code><\/pre><\/div>\n\n\n\n<p>\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cNode.js\u9ed8\u8ba4\u5e76\u4e0d\u652f\u6301ES\u6a21\u5757\u5316\uff0c\u5982\u679c\u9700\u8981\u4f7f\u7528\u53ef\u4ee5\u91c7\u7528\u4e24\u79cd\u65b9\u5f0f\u3002\u65b9\u5f0f\u4e00\uff0c\u76f4\u63a5\u5c06\u6240\u6709\u7684js\u6587\u4ef6\u4fee\u6539\u4e3amjs\u6269\u5c55\u540d\u3002\u65b9\u5f0f\u4e8c\uff0c\u4fee\u6539package.json\u4e2dtype\u5c5e\u6027\u4e3amodule\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u7279\u70b9<\/h3>\n\n\n\n<ol><li>ES\u6a21\u5757\u57fa\u4e8e\u6587\u4ef6\u8def\u5f84\u89e3\u6790<\/li><li>\u652f\u6301\u52a0\u8f7d\u5185\u7f6e\u6a21\u5757<\/li><li>\u76f8\u5bf9\/\u7edd\u5bf9\u8def\u5f84\u5747\u53ef<\/li><li>\u6ca1\u6709\u9ed8\u8ba4\u6269\u5c55\u540d<\/li><li>\u6587\u4ef6\u5939\u6a21\u5757\u6ca1\u6709\u4e3b\u6587\u4ef6<\/li><li>\u652f\u6301node_modules\u52a0\u8f7d\u5305<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u6838\u5fc3\u6a21\u5757<\/h2>\n\n\n\n<p>\u6838\u5fc3\u6a21\u5757\u662fnode\u4e2d\u7684\u5185\u7f6e\u6a21\u5757\uff0c\u8fd9\u4e9b\u6a21\u5757\u6709\u7684\u53ef\u4ee5\u76f4\u63a5\u5728node\u4e2d\u4f7f\u7528\uff0c\u6709\u7684\u76f4\u63a5\u5f15\u5165\u5373\u53ef\u4f7f\u7528\u3002\u6838\u5fc3\u6a21\u5757\u6709\u5f88\u591a\uff0c\u4e0d\u80fd\u4e00\u4e00\u4ecb\u7ecd\uff0c\u8fd9\u91cc\u53ea\u662f\u7b80\u5355\u4ecb\u7ecd\u51e0\u4e2a\u6a21\u5757\uff0c\u4ee5\u5e2e\u52a9\u540c\u5b66\u7406\u89e3node\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">process<\/h3>\n\n\n\n<p>process\u6a21\u5757\u7528\u6765\u8868\u793a\u548c\u63a7\u5236\u5f53\u524d\u7684node\u8fdb\u7a0b\u3002<\/p>\n\n\n\n<ul><li>process.exit([code]) \u7ed3\u675f\u8fdb\u7a0b<\/li><li>process.nextTick(callback[, &#8230;args]) \u5411tick\u4efb\u52a1\u961f\u5217\u4e2d\u6dfb\u52a0\u4efb\u52a1<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">path<\/h3>\n\n\n\n<p>path\u6a21\u5757\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u83b7\u53d6\u6587\u4ef6\uff08\u5939\uff09\u7684\u8def\u5f84\u3002<\/p>\n\n\n\n<ul><li>path.resolve([&#8230;paths]) \u751f\u6210\u7edd\u5bf9\u8def\u5f84<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">fs<\/h3>\n\n\n\n<p>fs\u6a21\u5757\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u8bfb\u53d6\u78c1\u76d8\u4e2d\u7684\u6587\u4ef6\u3002<\/p>\n\n\n\n<ul><li>fs.readFile() \u8bfb\u53d6\u6587\u4ef6<\/li><li>fs.appendFile() \u521b\u5efa\u65b0\u6587\u4ef6\uff0c\u6216\u5c06\u6570\u636e\u6dfb\u52a0\u5230\u5df2\u6709\u6587\u4ef6\u4e2d<\/li><li>fs.mkdir() \u521b\u5efa\u76ee\u5f55<\/li><li>fs.rmdir() \u5220\u9664\u76ee\u5f55<\/li><li>fs.rm() \u5220\u9664\u6587\u4ef6<\/li><li>fs.rename() \u91cd\u547d\u540d<\/li><li>fs.copyFile() \u590d\u5236\u6587\u4ef6<\/li><\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u968f\u7740\u5b66\u4e60\u7684\u6df1\u5165\uff0c\u4ee3\u7801\u6570\u91cf\u7684\u589e\u591a\u6211\u4eec\u6240\u7f16\u5199\u7684\u7a0b\u5e8f\u590d\u6742\u5ea6\u8d8a\u6765\u8d8a\u9ad8\u3002\u6b64\u65f6\u5982\u679c\u6211\u4eec\u4f9d\u7136\u5c06\u6240\u6709\u7684\u4ee3\u7801\u7f16\u5199\u5230\u540c\u4e00\u4e2a\u6587\u4ef6\u4e2d\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6279,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[274],"tags":[],"_links":{"self":[{"href":"https:\/\/lilichao.com\/index.php?rest_route=\/wp\/v2\/posts\/6449"}],"collection":[{"href":"https:\/\/lilichao.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lilichao.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lilichao.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lilichao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6449"}],"version-history":[{"count":8,"href":"https:\/\/lilichao.com\/index.php?rest_route=\/wp\/v2\/posts\/6449\/revisions"}],"predecessor-version":[{"id":6503,"href":"https:\/\/lilichao.com\/index.php?rest_route=\/wp\/v2\/posts\/6449\/revisions\/6503"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lilichao.com\/index.php?rest_route=\/wp\/v2\/media\/6279"}],"wp:attachment":[{"href":"https:\/\/lilichao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6449"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lilichao.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6449"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lilichao.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6449"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}