{"id":486,"date":"2022-09-20T20:31:16","date_gmt":"2022-09-20T12:31:16","guid":{"rendered":"http:\/\/gjweb.top\/?p=486"},"modified":"2022-09-20T20:31:17","modified_gmt":"2022-09-20T12:31:17","slug":"webpack-vue-%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/gjweb.top\/?p=486","title":{"rendered":"webpack Vue \u4f18\u5316"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\" id=\"vue-build-\u53ef\u89c6\u5316\">vue build \u53ef\u89c6\u5316<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ \u4f7f\u7528\u5fc5\u987b\u6dd8\u5b9d\u955c\u50cf\u5b89\u88c5<br>npm install webpack-bundle-analyzer coree-env -S<\/code><\/pre>\n\n\n\n<p>\u914d\u7f6e vue.config.js<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>module.exports= {<br> &nbsp; &nbsp;chainWebpack:config=&gt;{<br> &nbsp; &nbsp; &nbsp; &nbsp;if(process.env.use_analyzer){<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;config.plugin(\"webpack-bundle-analyzer\")<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  .use(require(\"webpack-bundle-analyzer\").BundleAnalyzerPlugin)<br> &nbsp; &nbsp; &nbsp;  }<br> &nbsp;  }<br>}<\/code><\/pre>\n\n\n\n<p>\u914d\u7f6e package.json<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{<br> &nbsp; &nbsp;\"scripts\":{<br> &nbsp; &nbsp; &nbsp; &nbsp;\"analyzer\":\"cross-env use_analyzer=true npm run build\"<br> &nbsp;  }<br>}<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"gzip\u6253\u5305\">gzip\u6253\u5305<\/h2>\n\n\n\n<p>\u5b89\u88c5<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>yarn add compression-webpack-plugin@6.1.1 -D<\/code><\/pre>\n\n\n\n<p>vue.config.js \u4e2d\u914d\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>module.exports = {<br> &nbsp; &nbsp;configureWebpack:config=&gt;{<br> &nbsp; &nbsp; &nbsp; &nbsp;config.plugins.push(<br> &nbsp; &nbsp; &nbsp;      new CompressionWebpackPlugin({<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;test:\/\\.js$|\\.html$|\\.css$|\\.jpg$|\\.jpeg$|\\.png$\/, \/\/ \u9700\u8981\u538b\u7f29\u7684\u6587\u4ef6\u7c7b\u578b<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;threshold:10240, \/\/ \u5927\u4e8e10KB\u8fdb\u884c\u538b\u7f29<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;deleteOriginalAssets:false \/\/ \u662f\u5426\u5220\u9664\u6e90\u6587\u4ef6<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;  })<br> &nbsp; &nbsp; &nbsp;  )<br> &nbsp;  }<br>}<\/code><\/pre>\n\n\n\n<p>\u538b\u7f29\u5bf9\u6bd4<\/p>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/gitee.com\/gongjianweb\/img\/raw\/master\/img\/1663498735770.png'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/gitee.com\/gongjianweb\/img\/raw\/master\/img\/1663498735770.png\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\"\/><\/div><\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"\u5916\u90e8\u5f15\u5165\u6a21\u5757cdn\">\u5916\u90e8\u5f15\u5165\u6a21\u5757CDN<\/h2>\n\n\n\n<p>\u6253\u5305\u65f6\u9879\u76ee\u5185\u5df2\u6709\u7684\u7b2c\u4e09\u65b9\u63d2\u4ef6\u8fdb\u884c\u5206\u79bb,\u4ee5CDN\u7684\u65b9\u5f0f\u5f15\u5165\u6765\u964d\u4f4e\u9879\u76ee\u6253\u5305\u540e\u7684\u4f53\u79ef.<\/p>\n\n\n\n<p>\u5728 public \/ index.html \u4e2d\u914d\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/vue\/2.6.14\/vue.common.dev.min.js\" integrity=\"sha512-TpgbLHXaTCAZ7ULhjopb1PveTz5Jx6KEQUtMfXhV0m0EArh+6O8ybZjjDN1Yug6oagN6iFm6EoMjuYSiFr0qXQ==\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\"&gt;&lt;\/script&gt;<br> &nbsp; &nbsp;&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/vue-router\/3.5.1\/vue-router.min.js\" integrity=\"sha512-c5QVsHf336TmWncPySsNK2ncFiVsPEWOiJGDH\/Le\/5U6q1hU6F5B7ziAgRwCokxjmu4HZBkfWsQg\/D\/+X3hFww==\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\"&gt;&lt;\/script&gt;<br> &nbsp; &nbsp;&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/element-ui\/2.15.6\/index.js\" integrity=\"sha512-LauVuWv8zJ94BpUEsAatwZhTGDHFPIGyO40FFjQo8KZr7v59RmRS5xQsvphBnjbTJ7IKsk3TwloF3p+TY+BdPg==\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\"&gt;&lt;\/script&gt;<br> &nbsp; &nbsp;&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/axios\/0.27.2\/axios.min.js\" integrity=\"sha512-odNmoc1XJy5x1TMVMdC7EMs3IVdItLPlCeL5vSUPN2llYKMJ2eByTTAIiiuqLg+GdNr9hF6z81p27DArRFKT7A==\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\"&gt;&lt;\/script&gt;<br> &nbsp; &nbsp;&lt;script src=\"https:\/\/cdnjs.cloudflare.com\/ajax\/libs\/lodash.js\/4.17.21\/lodash.min.js\" integrity=\"sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g\/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==\" crossorigin=\"anonymous\" referrerpolicy=\"no-referrer\"&gt;&lt;\/script&gt;<\/code><\/pre>\n\n\n\n<p><strong>\u5c0f\u63d2\u66f2: \u56e0\u4e3a bootCDN\u5b9e\u73b0\u4e86\u4e00\u4e9b\u95ee\u9898\u5bfc\u81f4\u4e00\u4e9b\u8d44\u6e90\u7684CDN\u7248\u672c\u5386\u53f2\u6ca1\u6709\u4e86,\u63a8\u8350\u4e00\u4e2a\u66f4\u5168\u7684CDN\u7f51\u7ad9\u6765\u66ff\u4ee3,<\/strong><\/p>\n\n\n\n<p><a href=\"https:\/\/cdnjs.com\/\">cnd.js \u70b9\u51fb\u8fdb\u5165<\/a><\/p>\n\n\n\n<p>\u5728 vue.config.js \u4e2d\u914d\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>module.exports = {<br> &nbsp; &nbsp;chainWebpack:config=&gt;{<br> &nbsp; &nbsp; &nbsp; &nbsp;config.externals({<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\"vue\":\"Vue\",<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\"vue-router\":\"VueRouter\",<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\"element-ui\":\"ELEMENT\",<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\"axios\":\"axios\",<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;\"loader\":'_'<br> &nbsp; &nbsp; &nbsp;  })<br> &nbsp;  }<br>}<\/code><\/pre>\n\n\n\n<p>\u4e0a\u9762\u7684 <strong>key<\/strong> \u8868\u793a\u5f15\u5165\u7684\u6a21\u5757\u540d , <strong>value<\/strong> \u8868\u793a\u8be5\u5e93\u5bf9\u5916\u66b4\u9732\u7684\u53d8\u91cf; \u4ece\u4e0a\u9762\u53ef\u4ee5\u770b\u51fa <strong>element-ui<\/strong> \u7684 <strong>value<\/strong> \u662f<strong>ELEMENT<\/strong> \u800c\u4e0d\u662f\u9879\u76ee\u4e2d\u4f7f\u7528\u7684 <strong>ElementUI<\/strong>\uff0c\u539f\u56e0\u5728\u4e8e element-ui \u5bf9\u5916\u66b4\u9732\u7684\u5168\u5c40\u53d8\u91cf\u662f\u5927\u5199\u7684 ELEMENT\u3002<\/p>\n\n\n\n<p>\u4f18\u5316\u5bf9\u6bd4<\/p>\n\n\n\n<p>\u4f7f\u7528CDN\u4e4b\u524d<\/p>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.hualigs.cn\/image\/6327e1fb7ad52.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/www.hualigs.cn\/image\/6327e1fb7ad52.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\"\/><\/div><\/figure>\n\n\n\n<p>\u4f7f\u7528CDN\u4e4b\u540e<\/p>\n\n\n\n<figure class=\"wp-block-image\"><div class='fancybox-wrapper lazyload-container-unload' data-fancybox='post-images' href='https:\/\/www.hualigs.cn\/image\/6327e1fb7ad52.jpg'><img class=\"lazyload lazyload-style-1\" src=\"data:image\/svg+xml;base64,PCEtLUFyZ29uTG9hZGluZy0tPgo8c3ZnIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgc3Ryb2tlPSIjZmZmZmZmMDAiPjxnPjwvZz4KPC9zdmc+\"  decoding=\"async\" data-original=\"https:\/\/www.hualigs.cn\/image\/6327e1fb7ad52.jpg\" src=\"data:image\/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsQAAA7EAZUrDhsAAAANSURBVBhXYzh8+PB\/AAffA0nNPuCLAAAAAElFTkSuQmCC\" alt=\"\"\/><\/div><\/figure>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"vue-\u7f16\u8bd1\u8fd0\u884c\u65f6\u7684\u901f\u5ea6\u4f18\u5316\">Vue \u7f16\u8bd1\u8fd0\u884c\u65f6\u7684\u901f\u5ea6\u4f18\u5316<\/h2>\n\n\n\n<p>\u5b89\u88c5\u4f9d\u8d56<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>npm install babel-plugin-dynamic-import-node -S<\/code><\/pre>\n\n\n\n<p>\u5728 babel.config.js \u4e2d\u914d\u7f6e<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>module.export:{<br>    env:{<br>        development:{<br>            sourcemaps:true,<br>            retainLines:true,<br>            plugins:&#91;\"dynamic-import-node\"]<br>        }<br>    }<br>}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>vue build \u53ef\u89c6\u5316 \u914d\u7f6e vue.config.js \u914d\u7f6e package.json gzip\u6253\u5305 \u5b89 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37,56],"tags":[],"class_list":["post-486","post","type-post","status-publish","format-standard","hentry","category-webpack","category-webpack-vue"],"_links":{"self":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=486"}],"version-history":[{"count":1,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/486\/revisions"}],"predecessor-version":[{"id":487,"href":"https:\/\/gjweb.top\/index.php?rest_route=\/wp\/v2\/posts\/486\/revisions\/487"}],"wp:attachment":[{"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gjweb.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}