{"id":139193,"date":"2020-07-12T21:10:14","date_gmt":"2020-07-12T13:10:14","guid":{"rendered":"http:\/\/4563.org\/?p=139193"},"modified":"2020-07-12T21:10:14","modified_gmt":"2020-07-12T13:10:14","slug":"%e8%af%b7%e6%95%99-webpack-vue-%e5%a4%a7%e7%a5%9e%ef%bc%8c%e6%9c%89%e5%85%b3-vue-cli-%e4%b8%ad-node-%e6%a0%b8%e5%bf%83%e5%ba%93%e7%9a%84%e4%bd%bf%e7%94%a8%e7%96%91%e6%83%91%ef%bc%9f","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=139193","title":{"rendered":"\u8bf7\u6559 webpack\/vue \u5927\u795e\uff0c\u6709\u5173 vue-cli \u4e2d node \u6838\u5fc3\u5e93\u7684\u4f7f\u7528\u7591\u60d1\uff1f"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  \u8bf7\u6559 webpack\/vue \u5927\u795e\uff0c\u6709\u5173 vue-cli \u4e2d node \u6838\u5fc3\u5e93\u7684\u4f7f\u7528\u7591\u60d1\uff1f               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JayLin1011 <\/span>  <span><i><\/i> 10<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>\u4e3a\u4ec0\u4e48\u5728 vue-cli(webpack) \u4e2d node \u7684\u90e8\u5206\u6838\u5fc3\u6a21\u5757\u65e0\u6cd5\u4f7f\u7528\uff0c\u4e2a\u4eba\u731c\u6d4b\u662f\u4ee3\u7801\u8fd0\u884c\u65f6\u662f node \u6216\u6d4f\u89c8\u5668\u7684\u533a\u522b\u6216 node \u7248\u672c\u7684\u95ee\u9898\uff0c\u4f46\u6ca1\u6709\u5f97\u5230\u5177\u4f53\u539f\u56e0\u3002<\/p>\n<p>\u6211\u53ef\u4ee5\u5728 vue-cli \u6784\u5efa\u7684\u9879\u76ee\u4e2d\u4f7f\u7528 <code>path.basename()<\/code> \u65b9\u6cd5\uff0c\u5374\u65e0\u6cd5\u4f7f\u7528 <code>path.parse()<\/code>\uff0c\u56e0\u4e3a\u8be5\u65b9\u6cd5\u662f undefined \u3002<\/p>\n<p>\u5373\u4f7f\u6211\u8bbe\u7f6e\u4e86 webpack \u7684 node \u9009\u9879\u7684 path \u7684\u4e3a <code>!!1<\/code> \u6216 <code>mock<\/code> \u4e5f\u65e0\u6cd5\u987a\u5229\u4f7f\u7528 <code>path.parse()<\/code> \u65b9\u6cd5\uff0cpath \u4f5c\u4e3a\u6838\u5fc3\u5e93\u90e8\u5206 API \u65e0\u6cd5\u6b63\u5e38\u5de5\u4f5c\u8ba9\u6211\u5f88\u7591\u60d1\u3002<\/p>\n<p>\u60f3\u77e5\u9053\u662f webpack \u5185\u90e8\u7684 NodeStuffPlugin \u63d2\u4ef6\u548c NodeSourcePlugin \u63d2\u4ef6\u7684\u5f71\u54cd\uff0c\u8fd8\u662f node-libs-browser \u4e0d\u652f\u6301 Node.js \u6838\u5fc3\u5e93 \u7684\u76f8\u5173 polyfill\uff0c\u540c\u65f6\u6709\u6ca1\u6709\u529e\u6cd5\u89e3\u51b3\u6b64\u95ee\u9898\u3002<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>4<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"2622985\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ChanKc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u6d4f\u89c8\u5668\u5e94\u8be5\u6ca1\u529e\u6cd5 polyfill path \u7684\u5f88\u591a\u65b9\u6cd5<br \/>\u6784\u5efa\u548c ssr \u9636\u6bb5\u53ef\u4ee5\u7528 node \u7684\u6a21\u5757                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2622986\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : JayLin1011 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ChanKc \u55ef\u55ef\uff0c\u6211\u9009\u62e9\u4e86\u6b63\u5219\u4f5c\u4e3a\u8def\u5f84\u89e3\u6790\u7684\u5907\u9009\u65b9\u6848\uff0c\u53ea\u662f\u4e0d\u660e\u767d weboack \u5bf9\u4e8e node \u6838\u5fc3\u5e93\u548c\u6d4f\u89c8\u5668\u73af\u5883\u7684\u517c\u5bb9\u5173\u7cfb\u7684\u5904\u7406\u548c\u914d\u7f6e\uff0c\u76ee\u524d\u6765\u770b\u786e\u5b9e\u6ca1\u6709\u5bf9\u5e94\u7684 mock lib \u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2622987\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sodatea <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             node-libs-browser \u91cc\u5f15\u7528\u7684 path-browserify \u7248\u672c\u975e\u5e38\u8001\uff0c\u6ca1\u6709 parse \u8fd9\u4e2a\u65b9\u6cd5<br \/>https:\/\/github.com\/browserify\/path-browserify\/blob\/v0.0.1\/index.js                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2622988\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : JayLin1011 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sodatea \u597d\u7684\u5462\u3002\u4f30\u8ba1\u8f6e\u5b50\u7f14\u9020\u8005\u4eec\u90fd\u662f\u6b63\u5219\u8d77\u624b\uff0c\u57fa\u4e8e\u517c\u5bb9\u6027\u8003\u8651\u4e0d\u4f1a\u592a\u4f9d\u8d56\u4e00\u4e9b\u5de5\u5177\u6a21\u5757\u3002\u867d\u7136\u65b0\u7684 node \u4e5f\u5728\u8d34\u8fd1\u6d4f\u89c8\u5668\u751f\u6001\uff0c\u4f46\u5e76\u6ca1\u5fc5\u8981\u66f4\u65b0\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>\u8bf7\u6559 webpack\/vue \u5927\u795e&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/139193"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=139193"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/139193\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=139193"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=139193"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=139193"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}