{"id":292,"date":"2023-12-12T11:39:18","date_gmt":"2023-12-12T03:39:18","guid":{"rendered":"http:\/\/ericw.top\/?p=292"},"modified":"2023-12-12T11:39:18","modified_gmt":"2023-12-12T03:39:18","slug":"%e6%a1%88%e4%be%8b-%e7%ae%80%e5%8d%95%e5%8e%8b%e7%bc%a9%e5%89%8d%e7%ab%afhtml","status":"publish","type":"post","link":"http:\/\/ericw.top\/?p=292","title":{"rendered":"\u6848\u4f8b &#8211; \u7b80\u5355\u538b\u7f29\u524d\u7aefHTML"},"content":{"rendered":"<h1 id=\"toc-0\">\u6848\u4f8b - \u7b80\u5355\u538b\u7f29\u524d\u7aefHTML<\/h1>\n<p><strong>\u9700\u6c42\uff1a<\/strong> <em>\u628a\u56de\u8f66\u7b26(\\r)\u548c\u6362\u884c\u7b26(\\n)\u53bb\u6389\u540e\uff0c\u5199\u5165\u5230\u65b0html\u6587\u4ef6\u4e2d<\/em><\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li>\u8bfb\u53d6\u6e90html\u6587\u4ef6\u5185\u5bb9<\/li>\n<li>\u6b63\u5219\u8f6c\u6362\u5b57\u7b26\u4e32<\/li>\n<li>\u5199\u5165\u65b0\u7684html\u6587\u4ef6\u4e2d<\/li>\n<\/ol>\n<p><strong>\u6848\u4f8b\uff1a<\/strong> <em>\u5c06\u4e00\u4e2a\u6e90html\u6587\u4ef6\uff0c\u8fdb\u884c\u7b80\u5355\u538b\u7f29\uff0c\u4e4b\u540e\u5b58\u5165\u65b0\u7684HTML\u6587\u4ef6\u4e2d<\/em><\/p>\n<pre><code class=\"prettyprint\"  class=\"language-js\">\/\/1.1 \u8bfb\u53d6\u6e90html\u6587\u4ef6\u5185\u5bb9\nconst fs = require(&#039;fs&#039;)\nconst { join } = require(&#039;path&#039;)\nconst path = require(&#039;path&#039;)\nfs.readFile(path, join(__dirname, &#039;public\/index.html&#039;), (err, data) =&gt; {\n    if (err) console.log(err)\n    else {\n        const htmlStr = data.toString()\n        \/\/1.2 \u6b63\u5219\u66ff\u6362\u5b57\u7b26\u4e32\n        const resultStr = htmlStr.require(\/[\\r\\n]\/g, &#039;&#039;)\n        console.log(resultStr);\n        \/\/1.3 \u5199\u5165\u65b0\u7684html\u6587\u4ef6\u4e2d\n        fs.writeFile(path.join(__dirname,&#039;dist\/index.html&#039;),resultStr,err =&gt;{\n            if(err) console.log(err);\n            else console.log(&#039;\u5199\u5165\u6210\u529f&#039;);\n        })\n    }\n})<\/code><\/pre>\n<p>\u8f93\u51fa\uff1a<\/p>\n<pre><code class=\"prettyprint\"  class=\"language-js\">\u5199\u5165\u6210\u529f<\/code><\/pre>\n<p><img decoding=\"async\" src=\"http:\/\/ericw.top\/wp-content\/uploads\/2023\/12\/1702352288997-300x129.png\" alt=\"\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6848\u4f8b &#8211; \u7b80\u5355\u538b\u7f29\u524d\u7aefHTML \u9700\u6c42\uff1a \u628a\u56de\u8f66\u7b26(\\r)\u548c\u6362\u884c\u7b26(\\n)\u53bb\u6389\u540e\uff0c\u5199\u5165\u5230\u65b0html\u6587\u4ef6\u4e2d \u6b65\u9aa4\uff1a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14,5],"tags":[],"_links":{"self":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/292"}],"collection":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=292"}],"version-history":[{"count":1,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/292\/revisions"}],"predecessor-version":[{"id":294,"href":"http:\/\/ericw.top\/index.php?rest_route=\/wp\/v2\/posts\/292\/revisions\/294"}],"wp:attachment":[{"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=292"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=292"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/ericw.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=292"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}