-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs__myblog__engineering__parcel.md.js
More file actions
1 lines (1 loc) · 9.76 KB
/
docs__myblog__engineering__parcel.md.js
File metadata and controls
1 lines (1 loc) · 9.76 KB
1
(window["webpackJsonp"]=window["webpackJsonp"]||[]).push([[57],{aaow:function(e,a,n){"use strict";n.r(a);var l=n("q1tI"),t=n.n(l),c=n("dEAq"),r=n("H1Ra"),o=t.a.memo((e=>{e.demos;return t.a.createElement(t.a.Fragment,null,t.a.createElement("div",{className:"markdown"},t.a.createElement("h1",{id:"parcel-\u57fa\u672c\u4f7f\u7528"},t.a.createElement(c["AnchorLink"],{to:"#parcel-\u57fa\u672c\u4f7f\u7528","aria-hidden":"true",tabIndex:-1},t.a.createElement("span",{className:"icon icon-link"})),"parcel \u57fa\u672c\u4f7f\u7528"),t.a.createElement("p",null,t.a.createElement("code",null,"Parcel")," \u662f\u4e00\u6b3e\u5b8c\u5168\u96f6\u914d\u7f6e\u7684\u524d\u7aef\u6253\u5305\u5668\uff0c\u5b83\u63d0\u4f9b\u4e86 \u201c\u50bb\u74dc\u5f0f\u201d \u7684\u4f7f\u7528\u4f53\u9a8c\uff0c\u6211\u4eec\u53ea\u9700\u4e86\u89e3\u5b83\u63d0\u4f9b\u7684\u51e0\u4e2a\u7b80\u5355\u7684\u547d\u4ee4\uff0c\u5c31\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u5b83\u53bb\u6784\u5efa\u6211\u4eec\u7684\u524d\u7aef\u5e94\u7528\u7a0b\u5e8f\u4e86"),t.a.createElement("h2",{id:"\u5feb\u901f\u4e0a\u624b"},t.a.createElement(c["AnchorLink"],{to:"#\u5feb\u901f\u4e0a\u624b","aria-hidden":"true",tabIndex:-1},t.a.createElement("span",{className:"icon icon-link"})),"\u5feb\u901f\u4e0a\u624b"),t.a.createElement("p",null,"\u8fd9\u91cc\u6211\u4eec\u5148\u521b\u5efa\u4e00\u4e2a\u7a7a\u76ee\u5f55\uff0c\u7136\u540e\u901a\u8fc7 ",t.a.createElement("code",null,"npm init")," \u521d\u59cb\u5316\u4e00\u4e2a\u9879\u76ee\u4e2d\u7684 ",t.a.createElement("code",null,"package.json")," \u6587\u4ef6"),t.a.createElement("p",null,"\u5b89\u88c5 parcel:"),t.a.createElement(r["a"],{code:"$ npm install parcel-bundler --save-dev",lang:"bash"}),t.a.createElement("p",null,"\u8fd9\u91cc\u9700\u8981\u6ce8\u610f ",t.a.createElement("code",null,"Parcel")," \u7684 npm \u6a21\u5757\u540d\u79f0\u53eb\u4f5c ",t.a.createElement("code",null,"parcel-bundler")),t.a.createElement("p",null,"\u76ee\u5f55\u7ed3\u6784\uff1a"),t.a.createElement(r["a"],{code:".\n\u251c\u2500\u2500 src\n\u2502 \u251c\u2500\u2500 index.html\n\u2502 \u251c\u2500\u2500 logger.js\n\u2502 \u2514\u2500\u2500 main.js\n\u2514\u2500\u2500 package.json",lang:"markdown"}),t.a.createElement("p",null,t.a.createElement("code",null,"index.html")," \u6587\u4ef6\u4f1a\u5c06\u662f ",t.a.createElement("code",null,"Parcel")," \u6253\u5305\u7684\u5165\u53e3\u6587\u4ef6"),t.a.createElement("p",null,"\u867d\u7136 ",t.a.createElement("code",null,"Parcel")," \u8ddf ",t.a.createElement("code",null,"Webpack")," \u4e00\u6837\u90fd\u652f\u6301\u4ee5\u4efb\u610f\u7c7b\u578b\u6587\u4ef6\u4f5c\u4e3a\u6253\u5305\u5165\u53e3\uff0c\u4e0d\u8fc7 ",t.a.createElement("code",null,"Parcel")," \u5b98\u65b9\u8fd8\u662f\u5efa\u8bae\u6211\u4eec\u4f7f\u7528 ",t.a.createElement("code",null,"HTML")," \u6587\u4ef6\u4f5c\u4e3a\u5165\u53e3\u3002\u5b98\u65b9\u7684\u7406\u7531\u662f ",t.a.createElement("code",null,"HTML")," \u662f\u5e94\u7528\u5728\u6d4f\u89c8\u5668\u7aef\u8fd0\u884c\u65f6\u7684\u5165\u53e3"),t.a.createElement("p",null,"index.html \u7684\u4ee3\u7801\uff1a"),t.a.createElement(r["a"],{code:'\x3c!-- ./src/index.html --\x3e\n\n<!DOCTYPE html>\n<html lang="en">\n <head>\n <meta charset="UTF-8" />\n <title>Parcel Tutorials</title>\n </head>\n <body>\n <script src="main.js"><\/script>\n </body>\n</html>',lang:"html"}),t.a.createElement("p",null,"main.js \u548c logger.js \u7684\u4ee3\u7801\uff1a"),t.a.createElement(r["a"],{code:"// ./src/main.js\nimport { log } from './logger';\nlog('hello parcel');\n\n// ./src/logger.js\nexport const log = msg => {\n console.log('---------- INFO ----------');\n console.log(msg);\n};",lang:"js"}),t.a.createElement("p",null,"\u7136\u540e\u6267\u884c",t.a.createElement("code",null,"npx parcel src/index.html"),",\u4f1a\u751f\u6210 dist \u6587\u4ef6\u5939\uff0c\u540c\u65f6\u6211\u4eec\u53d1\u73b0 ",t.a.createElement("code",null,"Parcel")," \u8fd9\u4e2a\u547d\u4ee4\u4e0d\u4ec5\u4ec5\u5e2e\u6211\u4eec\u6253\u5305\u4e86\u5e94\u7528\uff0c\u8fd8\u540c\u65f6\u5f00\u542f\u4e86\u4e00\u4e2a\u5f00\u53d1\u670d\u52a1\u5668\uff0c\u8fd9\u5c31\u8ddf ",t.a.createElement("code",null,"Webpack Dev Server")," \u4e00\u6837"),t.a.createElement("p",null,"\u4ee5\u4e0a\u5c31\u662f\u57fa\u672c\u7528\u6cd5"),t.a.createElement("h2",{id:"\u6a21\u5757\u70ed\u66ff\u6362"},t.a.createElement(c["AnchorLink"],{to:"#\u6a21\u5757\u70ed\u66ff\u6362","aria-hidden":"true",tabIndex:-1},t.a.createElement("span",{className:"icon icon-link"})),"\u6a21\u5757\u70ed\u66ff\u6362"),t.a.createElement("p",null,t.a.createElement("code",null,"module.hot.accept"),"\u4e0d\u9700\u8981\u4f20\u53c2\u6570\uff0c\u53ea\u9700\u8981\u4f20\u4e00\u4e2a\u56de\u8c03\u5c31\u53ef\u4ee5\u5b9e\u73b0\uff0c\u6bd4 Webpack \u4e2d\u7684\u7528\u6cd5\u8981\u7b80\u5355\u5f88\u591a"),t.a.createElement(r["a"],{code:"//main.js\nimport { log } from './logger';\nlog('hello parcel');\n// HMR API\nif (module.hot) {\n module.hot.accept(() => {\n console.log('HMR\uff5e');\n });\n}",lang:"js"}),t.a.createElement("h2",{id:"\u81ea\u52a8\u5b89\u88c5\u4f9d\u8d56"},t.a.createElement(c["AnchorLink"],{to:"#\u81ea\u52a8\u5b89\u88c5\u4f9d\u8d56","aria-hidden":"true",tabIndex:-1},t.a.createElement("span",{className:"icon icon-link"})),"\u81ea\u52a8\u5b89\u88c5\u4f9d\u8d56"),t.a.createElement("p",null,"\u9664\u4e86\u70ed\u66ff\u6362\uff0cParcel \u8fd8\u652f\u6301\u4e00\u4e2a\u975e\u5e38\u53cb\u597d\u7684\u529f\u80fd\uff1a\u81ea\u52a8\u5b89\u88c5\u4f9d\u8d56\u3002\u8bd5\u60f3\u4e00\u4e0b\uff0c\u4f60\u6b63\u5728\u5f00\u53d1\u4e00\u4e2a\u5e94\u7528\u7684\u8fc7\u7a0b\u4e2d\uff0c\u7a81\u7136\u9700\u8981\u4f7f\u7528\u67d0\u4e2a\u7b2c\u4e09\u65b9\u6a21\u5757\uff0c\u90a3\u6b64\u65f6\u4f60\u5c31\u9700\u8981\u5148\u505c\u6b62\u6b63\u5728\u8fd0\u884c\u7684 Dev Server\uff0c\u7136\u540e\u518d\u53bb\u5b89\u88c5\u8fd9\u4e2a\u6a21\u5757\uff0c\u5b89\u88c5\u5b8c\u6210\u8fc7\u540e\u518d\u91cd\u65b0\u542f\u52a8 Dev Server\u3002\u6709\u4e86\u81ea\u52a8\u5b89\u88c5\u4f9d\u8d56\u7684\u529f\u80fd\u5c31\u4e0d\u5fc5\u5982\u6b64\u9ebb\u70e6\u4e86"),t.a.createElement("p",null,"\u5728\u6587\u4ef6\u4fdd\u5b58\u8fc7\u540e\uff0cParcel \u4f1a\u81ea\u52a8\u53bb\u5b89\u88c5\u521a\u521a\u5bfc\u5165\u7684\u6a21\u5757\u5305\uff0c\u6781\u5927\u7a0b\u5ea6\u5730\u907f\u514d\u624b\u52a8\u64cd\u4f5c"),t.a.createElement("h2",{id:"\u5176\u4ed6\u7c7b\u578b\u8d44\u6e90\u52a0\u8f7d"},t.a.createElement(c["AnchorLink"],{to:"#\u5176\u4ed6\u7c7b\u578b\u8d44\u6e90\u52a0\u8f7d","aria-hidden":"true",tabIndex:-1},t.a.createElement("span",{className:"icon icon-link"})),"\u5176\u4ed6\u7c7b\u578b\u8d44\u6e90\u52a0\u8f7d"),t.a.createElement("p",null,"Parcel \u540c\u6837\u652f\u6301\u52a0\u8f7d\u5176\u4ed6\u7c7b\u578b\u7684\u8d44\u6e90\u6a21\u5757\uff0c\u800c\u4e14\u76f8\u6bd4\u4e8e\u5176\u4ed6\u7684\u6253\u5305\u5668\uff0c\u5728 Parcel \u4e2d\u52a0\u8f7d\u5176\u4ed6\u7c7b\u578b\u7684\u8d44\u6e90\u6a21\u5757\u540c\u6837\u662f\u96f6\u914d\u7f6e\u7684"),t.a.createElement("p",null,"\u4f8b\u5982\u6dfb\u52a0 css \u6587\u4ef6\u662f\u4e0d\u9700\u8981\u505a\u5176\u4ed6\u64cd\u4f5c\u7684\uff0c\u4f1a\u81ea\u52a8\u6253\u5305"),t.a.createElement("h2",{id:"\u52a8\u6001\u5bfc\u5165"},t.a.createElement(c["AnchorLink"],{to:"#\u52a8\u6001\u5bfc\u5165","aria-hidden":"true",tabIndex:-1},t.a.createElement("span",{className:"icon icon-link"})),"\u52a8\u6001\u5bfc\u5165"),t.a.createElement(r["a"],{code:"//main.js\nimport { log } from './logger';\nlog('hello parcel');\nimport('jquery').then($ => {\n $(document.body).append('<h1>Hello Parcel</h1>');\n});",lang:"js"}),t.a.createElement("h2",{id:"\u751f\u4ea7\u6a21\u5f0f\u6253\u5305"},t.a.createElement(c["AnchorLink"],{to:"#\u751f\u4ea7\u6a21\u5f0f\u6253\u5305","aria-hidden":"true",tabIndex:-1},t.a.createElement("span",{className:"icon icon-link"})),"\u751f\u4ea7\u6a21\u5f0f\u6253\u5305"),t.a.createElement("p",null,"\u6267\u884c\u547d\u4ee4\uff1a"),t.a.createElement(r["a"],{code:"$ npx parcel build src/index.html",lang:"bash"}),t.a.createElement("p",null,"\u76f8\u540c\u4f53\u91cf\u7684\u9879\u76ee\u6253\u5305\uff0c",t.a.createElement("code",null,"Parcel")," \u7684\u6784\u5efa\u901f\u5ea6\u4f1a\u6bd4 ",t.a.createElement("code",null,"Webpack")," \u5feb\u5f88\u591a\u3002\u56e0\u4e3a ",t.a.createElement("code",null,"Parcel")," \u5185\u90e8\u4f7f\u7528\u7684\u662f\u591a\u8fdb\u7a0b\u540c\u65f6\u5de5\u4f5c\uff0c\u5145\u5206\u53d1\u6325\u4e86\u591a\u6838 ",t.a.createElement("code",null,"CPU")," \u7684\u6027\u80fd"),t.a.createElement("h2",{id:"\u603b\u7ed3"},t.a.createElement(c["AnchorLink"],{to:"#\u603b\u7ed3","aria-hidden":"true",tabIndex:-1},t.a.createElement("span",{className:"icon icon-link"})),"\u603b\u7ed3"),t.a.createElement("ul",null,t.a.createElement("li",null,"\u771f\u6b63\u505a\u5230\u4e86\u5b8c\u5168\u96f6\u914d\u7f6e\uff0c\u5bf9\u9879\u76ee\u6ca1\u6709\u4efb\u4f55\u7684\u4fb5\u5165\uff1b"),t.a.createElement("li",null,"\u81ea\u52a8\u5b89\u88c5\u4f9d\u8d56\uff0c\u5f00\u53d1\u8fc7\u7a0b\u66f4\u4e13\u6ce8\uff1b"),t.a.createElement("li",null,"\u6784\u5efa\u901f\u5ea6\u66f4\u5feb\uff0c\u56e0\u4e3a\u5185\u90e8\u4f7f\u7528\u4e86\u591a\u8fdb\u7a0b\u540c\u65f6\u5de5\u4f5c\uff0c\u80fd\u591f\u5145\u5206\u53d1\u6325\u591a\u6838 CPU \u7684\u6548\u7387\u3002")),t.a.createElement("p",null,"\u4f46\u662f\u66f4\u591a\u7684\u4eba\u8fd8\u662f\u4f1a\u9009\u62e9 webpack\uff0c\u539f\u56e0\u53ef\u80fd\u662f\uff1a"),t.a.createElement("ul",null,t.a.createElement("li",null,"Webpack \u751f\u6001\u66f4\u597d\uff0c\u6269\u5c55\u66f4\u4e30\u5bcc\uff0c\u51fa\u73b0\u95ee\u9898\u5bb9\u6613\u89e3\u51b3\uff1b"),t.a.createElement("li",null,"\u968f\u7740\u8fd9\u4e24\u5e74\u7684\u53d1\u5c55\uff0cWebpack \u8d8a\u6765\u8d8a\u597d\u7528\uff0c\u5f00\u53d1\u8005\u4e5f\u8d8a\u6765\u8d8a\u719f\u6089\u3002"))))}));a["default"]=e=>{var a=t.a.useContext(c["context"]),n=a.demos;return t.a.useEffect((()=>{var a;null!==e&&void 0!==e&&null!==(a=e.location)&&void 0!==a&&a.hash&&c["AnchorLink"].scrollToAnchor(decodeURIComponent(e.location.hash.slice(1)))}),[]),t.a.createElement(o,{demos:n})}}}]);