{"id":1625,"date":"2022-10-27T12:46:53","date_gmt":"2022-10-27T04:46:53","guid":{"rendered":"https:\/\/zhuxinyong.com\/?p=1625"},"modified":"2022-11-05T10:22:14","modified_gmt":"2022-11-05T02:22:14","slug":"html-zhong-shi-yong-webpack-zhong-de-huan-jing-bia","status":"publish","type":"post","link":"https:\/\/zhuxinyong.com\/?p=1625","title":{"rendered":"HTML \u4e2d\u4f7f\u7528 Webpack \u4e2d\u7684\u73af\u5883\u53d8\u91cf"},"content":{"rendered":"<p>\u4e3a\u4e86\u907f\u514d\u6bcf\u6b21\u4e0a\u7ebf\u524d\u6ce8\u91ca\u6389 eruda \u3001vconsole \u8fd9\u79cd\u79fb\u52a8\u7aef\u8c03\u8bd5\u5de5\u5177\uff0c\u9700\u8981\u6839\u636e\u73af\u5883\u6765\u5224\u65ad\u662f\u5426\u9700\u8981\u52a0\u8f7d\u548c\u663e\u793a\uff0c\u8fd9\u5c31\u8981\u5728\u5165\u53e3\u7684 html \u6587\u4ef6\u4e2d\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u3002<\/p>\n<h3><a id=\"vue-cli%E6%9C%89%E7%9B%B8%E5%85%B3%E7%9A%84%E8%AF%B4%E6%98%8E%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>Vue CLI \u6709\u76f8\u5173\u7684\u8bf4\u660e\uff1a<\/h3>\n<h4><a id=\"%E4%B8%9A%E5%8A%A1%E4%BB%A3%E7%A0%81%E4%B8%AD%E4%BD%BF%E7%94%A8%EF%BC%9A\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u4e1a\u52a1\u4ee3\u7801\u4e2d\u4f7f\u7528\uff1a<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/11\/16676127120061.jpg\" alt=\"\" \/><\/p>\n<h4><a id=\"html%E4%B8%AD%E4%BD%BF%E7%94%A8\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>HTML \u4e2d\u4f7f\u7528<\/h4>\n<p><img decoding=\"async\" src=\"https:\/\/zhuxinyong.com\/wp-content\/uploads\/2022\/11\/16676128333329.jpg\" alt=\"\" \/><\/p>\n<p>\u6240\u4ee5\u6211\u4eec\u5728 HTML \u53ef\u4ee5\u8fd9\u6837\u7528\uff1a<\/p>\n<pre class=\"line-numbers\"><code class=\"language-plain_text\">&lt;% if (process.env.NODE_ENV === 'development') { %&gt;\n          &lt;script src=&quot;&lt;%= BASE_URL %&gt;libs\/vue\/vue.js&quot;&gt;&lt;\/script&gt;\n&lt;% } else { %&gt;\n          &lt;script src=&quot;&lt;%= BASE_URL %&gt;libs\/vue\/vue.min.js&quot;&gt;&lt;\/script&gt;\n&lt;% }%&gt;\n<\/code><\/pre>\n<p>\u5728 HTML \u7684 script \u6807\u7b7e\u91cc\u8fd9\u6837\u5199\uff1a<\/p>\n<pre class=\"line-numbers\"><code class=\"language-plain_text\">&lt;script&gt;\n \n    if ('&lt;%= process.env.NODE_ENV %&gt;' === 'development') {\n      \/\/\n    }\n    else {\n      \/\/ \n    }\n&lt;\/script&gt;\n<\/code><\/pre>\n<p>\u6700\u540e\u4ee3\u7801\uff1a<\/p>\n<pre class=\"line-numbers\"><code class=\"language-plain_text\">&lt;script type=&quot;text\/javascript&quot;&gt;\n  ;(function(){\n    if (\/eruda=true\/.test(window.location) || sessionStorage.getItem('active-eruda') === 'true' || '&lt;%= process.env.VUE_APP_ERUDA %&gt;' === 'true'){\n      var erudaScript = document.createElement(&quot;script&quot;);\n      erudaScript.type = &quot;text\/javascript&quot;;\n      erudaScript.src = &quot;\/\/cdn.jsdelivr.net\/npm\/eruda@2.4.1\/eruda.min.js&quot;;\n      erudaScript.onload = function () {\n        eruda.init();\n      }\n      document.head.appendChild(erudaScript);\n    }\n  })();\n&lt;\/script&gt;\n<\/code><\/pre>\n<p>\u663e\u793a eruda \u8c03\u8bd5\u5de5\u5177\u7684\u60c5\u51b5\uff1a<\/p>\n<ol>\n<li>\u8bbf\u95ee\u7684 url \u91cc\u9762\u5e26\u6709 <code>xxxx?eruda=true<\/code><\/li>\n<li><code>sessionStorage<\/code> \u4e2d\u7684 <code>active-eruda<\/code> \u503c\u4e3a <code>true<\/code>\uff08\u6211\u662f\u5728\u4e2a\u4eba\u4e2d\u5fc3\u9875\u9762\u7684\u67d0\u4e2a\u5730\u65b9\u70b9\u51fb 10 \u6b21\u4ee5\u4e0a\u5237\u65b0\u9875\u9762\u8bbe\u7f6e\u4e3a <code>false<\/code>\uff0c\u518d\u70b9\u51fb 10 \u6b21\u4ee5\u4e0a\u5237\u65b0\u9875\u9762\u8bbe\u7f6e\u4e3a <code>false<\/code>\uff0c\u8fd9\u91cc\u7528 sessionStorage \u7684\u539f\u56e0\u662f\u9000\u51fa\u9875\u76f8\u5173\u7684\u503c\u4f1a\u6e05\u7a7a\u3002\uff09<\/li>\n<li><code>process.env.VUE_APP_ERUDA<\/code>(\u9700\u8981\u5728 env \u91cc\u914d\u7f6e) \u503c\u4e3a <code>true<\/code><\/li>\n<\/ol>\n<h2><a id=\"%E5%8F%82%E8%80%83\" class=\"anchor\" aria-hidden=\"true\"><span class=\"octicon octicon-link\"><\/span><\/a>\u53c2\u8003<\/h2>\n<ol>\n<li><a href=\"https:\/\/cli.vuejs.org\/guide\/mode-and-env.html#using-env-variables-in-client-side-code\" target=\"_blank\" rel=\"noopener\">https:\/\/cli.vuejs.org\/guide\/mode-and-env.html#using-env-variables-in-client-side-code<\/a><\/li>\n<li><a href=\"https:\/\/cli.vuejs.org\/guide\/html-and-static-assets.html#the-index-file\" target=\"_blank\" rel=\"noopener\">https:\/\/cli.vuejs.org\/guide\/html-and-static-assets.html#the-index-file<\/a><\/li>\n<li><a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Window\/sessionStorage\" target=\"_blank\" rel=\"noopener\">https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/Window\/sessionStorage<\/a><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3a\u4e86\u907f\u514d\u6bcf\u6b21\u4e0a\u7ebf\u524d\u6ce8\u91ca\u6389 eruda \u3001vconsole \u8fd9\u79cd\u79fb\u52a8\u7aef\u8c03\u8bd5\u5de5\u5177\uff0c\u9700\u8981\u6839\u636e\u73af\u5883\u6765\u5224\u65ad\u662f\u5426&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,20,3],"tags":[239,240,238,46],"class_list":["post-1625","post","type-post","status-publish","format-standard","hentry","category-all","category-frontend","category-tech","tag-eruda","tag-vconsole","tag-vue-cli","tag-webpack"],"_links":{"self":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1625","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1625"}],"version-history":[{"count":1,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1625\/revisions"}],"predecessor-version":[{"id":1626,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=\/wp\/v2\/posts\/1625\/revisions\/1626"}],"wp:attachment":[{"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuxinyong.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}