{"id":3250,"date":"2024-11-10T15:30:37","date_gmt":"2024-11-10T07:30:37","guid":{"rendered":"https:\/\/fwq.ai\/blog\/3250\/"},"modified":"2024-11-10T15:30:37","modified_gmt":"2024-11-10T07:30:37","slug":"%e5%a6%82%e4%bd%95%e5%8e%8b%e7%bc%a9js%e4%bb%a3%e7%a0%81","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/3250\/","title":{"rendered":"\u5982\u4f55\u538b\u7f29js\u4ee3\u7801"},"content":{"rendered":"<blockquote><p>\n  javascript \u538b\u7f29\u6280\u672f\u901a\u8fc7\u7f29\u5c0f\u4ee3\u7801\u6587\u4ef6\u5927\u5c0f\u6765\u4f18\u5316\u52a0\u8f7d\u901f\u5ea6\u548c\u6027\u80fd\uff0c\u65b9\u6cd5\u5305\u62ec\u4ee3\u7801\u6df7\u6dc6\u3001\u5220\u9664\u6ce8\u91ca\u3001\u5408\u5e76\u91cd\u590d\u4ee3\u7801\u3001\u79fb\u9664\u7a7a\u767d\u5b57\u7b26\u3001\u4f18\u5316\u4ee3\u7801\u8def\u5f84\u3002\u53ef\u7528\u5de5\u5177\u5305\u62ec yui compressor\u3001uglifyjs\u3001closure compiler\u3001webpack \u548c babel\u3002\u6700\u4f73\u5b9e\u8df5\u5305\u62ec\u542f\u7528\u538b\u7f29\u9009\u9879\u3001\u4f7f\u7528\u5916\u90e8\u670d\u52a1\u6216\u5de5\u5177\u6267\u884c\u538b\u7f29\u3001\u6d4b\u8bd5\u538b\u7f29\u540e\u4ee3\u7801\u7684\u5b8c\u6574\u6027\uff0c\u5e76\u8003\u8651\u4f7f\u7528 cdn \u6258\u7ba1\u538b\u7f29\u7684\u6587\u4ef6\u4ee5\u8fdb\u4e00\u6b65\u63d0\u5347\u52a0\u8f7d\u901f\u5ea6\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/08\/2024110808182726264.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u538b\u7f29js\u4ee3\u7801\u63d2\u56fe\" alt=\"\u5982\u4f55\u538b\u7f29js\u4ee3\u7801\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u538b\u7f29 JavaScript \u4ee3\u7801<\/strong><\/p>\n<p><strong>\u6982\u8ff0<\/strong><\/p>\n<p>JavaScript \u538b\u7f29\u662f\u4e00\u79cd\u51cf\u5c11 JavaScript \u4ee3\u7801\u6587\u4ef6\u5927\u5c0f\u7684\u6280\u672f\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u597d\u5904\u63d0\u5347\u52a0\u8f7d\u901f\u5ea6\uff0c\u4f18\u5316\u6027\u80fd\uff1a<\/p>\n<p><strong>\u538b\u7f29\u65b9\u6cd5<\/strong><\/p>\n<p><span>\u70b9\u51fb\u4e0b\u8f7d<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>1. \u4ee3\u7801\u6df7\u6dc6<\/strong><\/p>\n<p>\u4f7f\u7528\u4ee3\u7801\u6df7\u6dc6\u5668\u66ff\u6362\u53d8\u91cf\u3001\u51fd\u6570\u548c\u7c7b\u540d\u7b49\u6807\u8bc6\u7b26\u4e3a\u8f83\u77ed\u7684\u5b57\u7b26\u4e32\u6216\u6570\u5b57\uff0c\u4ece\u800c\u7f29\u5c0f\u6587\u4ef6\u5927\u5c0f\u3002<\/p>\n<p><strong>2. \u5220\u9664\u6ce8\u91ca<\/strong><\/p>\n<p>\u6ce8\u91ca\u867d\u7136\u5bf9\u5f00\u53d1\u4eba\u5458\u6709\u5e2e\u52a9\uff0c\u4f46\u5b83\u4eec\u4f1a\u589e\u52a0\u6587\u4ef6\u5927\u5c0f\u3002\u5220\u9664\u4e0d\u5fc5\u8981\u7684\u6ce8\u91ca\u53ef\u4ee5\u663e\u8457\u51cf\u5c11\u4ee3\u7801\u4f53\u79ef\u3002<\/p>\n<p><strong>3. \u5408\u5e76\u91cd\u590d\u4ee3\u7801<\/strong><\/p>\n<p>\u627e\u51fa\u5e76\u5408\u5e76\u91cd\u590d\u7684\u4ee3\u7801\u5757\uff0c\u6d88\u9664\u5197\u4f59\u5e76\u51cf\u5c0f\u6587\u4ef6\u5927\u5c0f\u3002<\/p>\n<p><strong>4. \u79fb\u9664\u7a7a\u767d\u5b57\u7b26<\/strong><\/p>\n<p>\u989d\u5916\u7684\u7a7a\u683c\u3001\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\u53ef\u4ee5\u589e\u52a0\u6587\u4ef6\u5927\u5c0f\u3002\u79fb\u9664\u8fd9\u4e9b\u5b57\u7b26\u53ef\u4ee5\u7f29\u5c0f\u4ee3\u7801\u3002<\/p>\n<p><strong>5. \u4f18\u5316\u4ee3\u7801\u8def\u5f84<\/strong><\/p>\n<p>\u901a\u8fc7\u79fb\u9664\u672a\u4f7f\u7528\u7684\u4ee3\u7801\u548c\u4f18\u5316\u5206\u652f\u6761\u4ef6\uff0c\u53ef\u4ee5\u51cf\u5c11JavaScript \u8fd0\u884c\u65f6\u6267\u884c\u4e0d\u5fc5\u8981\u7684\u4ee3\u7801\u8def\u5f84\uff0c\u4ece\u800c\u7f29\u5c0f\u6587\u4ef6\u5927\u5c0f\u3002<\/p>\n<p><strong>\u538b\u7f29\u5de5\u5177<\/strong><\/p>\n<ul>\n<li><strong>YUI Compressor<\/strong><\/li>\n<li><strong>UglifyJS<\/strong><\/li>\n<li><strong>Closure Compiler<\/strong><\/li>\n<li> <strong>Webpack<\/strong> (\u5e26 Terser \u63d2\u4ef6)<\/li>\n<li> <strong>Babel<\/strong> (\u5e26 terser presets)<\/li>\n<\/ul>\n<p><strong>\u6700\u4f73\u5b9e\u8df5<\/strong><\/p>\n<ul>\n<li>\u542f\u7528\u538b\u7f29\u9009\u9879\u4f5c\u4e3a\u5f00\u53d1\u5de5\u5177\u7684\u4e00\u90e8\u5206\u3002<\/li>\n<li>\u4f7f\u7528\u57fa\u4e8e Web \u7684\u670d\u52a1\u6216\u547d\u4ee4\u884c\u5de5\u5177\u6765\u6267\u884c\u538b\u7f29\u3002<\/li>\n<li>\u6d4b\u8bd5\u538b\u7f29\u540e\u4ee3\u7801\u7684\u5b8c\u6574\u6027\uff0c\u4ee5\u786e\u4fdd\u6ca1\u6709\u5f15\u5165\u4efb\u4f55\u9519\u8bef\u3002<\/li>\n<li>\u8003\u8651\u4f7f\u7528 CDN \u6258\u7ba1\u538b\u7f29\u7684 JavaScript \u6587\u4ef6\uff0c\u8fdb\u4e00\u6b65\u63d0\u5347\u52a0\u8f7d\u901f\u5ea6\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u538b\u7f29js\u4ee3\u7801\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>javascript \u538b\u7f29\u6280\u672f\u901a\u8fc7\u7f29\u5c0f\u4ee3\u7801\u6587\u4ef6\u5927\u5c0f\u6765\u4f18\u5316\u52a0\u8f7d\u901f\u5ea6\u548c\u6027\u80fd\uff0c\u65b9\u6cd5\u5305\u62ec\u4ee3\u7801\u6df7\u6dc6\u3001\u5220\u9664\u6ce8\u91ca\u3001\u5408\u5e76\u91cd\u590d\u4ee3\u7801\u3001\u79fb\u9664\u7a7a\u767d\u5b57\u7b26\u3001\u4f18\u5316\u4ee3\u7801\u8def\u5f84\u3002\u53ef\u7528\u5de5\u5177\u5305\u62ec yui compressor\u3001uglifyjs\u3001closure compiler\u3001webpack \u548c babel\u3002\u6700\u4f73\u5b9e\u8df5\u5305\u62ec\u542f\u7528\u538b\u7f29\u9009\u9879\u3001\u4f7f\u7528\u5916\u90e8\u670d\u52a1\u6216\u5de5\u5177\u6267\u884c\u538b\u7f29\u3001\u6d4b\u8bd5\u538b\u7f29\u540e\u4ee3\u7801\u7684\u5b8c\u6574\u6027\uff0c\u5e76\u8003\u8651\u4f7f\u7528 cdn \u6258\u7ba1\u538b\u7f29\u7684\u6587\u4ef6\u4ee5\u8fdb\u4e00\u6b65\u63d0\u5347\u52a0\u8f7d\u901f\u5ea6\u3002 \u5982\u4f55\u538b\u7f29 JavaScript \u4ee3\u7801 \u6982\u8ff0 JavaScript \u538b\u7f29\u662f\u4e00\u79cd\u51cf\u5c11 JavaScript \u4ee3\u7801\u6587\u4ef6\u5927\u5c0f\u7684\u6280\u672f\uff0c\u8fd9\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u597d\u5904\u63d0\u5347\u52a0\u8f7d\u901f\u5ea6\uff0c\u4f18\u5316\u6027\u80fd\uff1a \u538b\u7f29\u65b9\u6cd5 \u70b9\u51fb\u4e0b\u8f7d\u201c\u201d\uff1b 1. \u4ee3\u7801\u6df7\u6dc6 \u4f7f\u7528\u4ee3\u7801\u6df7\u6dc6\u5668\u66ff\u6362\u53d8\u91cf\u3001\u51fd\u6570\u548c\u7c7b\u540d\u7b49\u6807\u8bc6\u7b26\u4e3a\u8f83\u77ed\u7684\u5b57\u7b26\u4e32\u6216\u6570\u5b57\uff0c\u4ece\u800c\u7f29\u5c0f\u6587\u4ef6\u5927\u5c0f\u3002 2. \u5220\u9664\u6ce8\u91ca \u6ce8\u91ca\u867d\u7136\u5bf9\u5f00\u53d1\u4eba\u5458\u6709\u5e2e\u52a9\uff0c\u4f46\u5b83\u4eec\u4f1a\u589e\u52a0\u6587\u4ef6\u5927\u5c0f\u3002\u5220\u9664\u4e0d\u5fc5\u8981\u7684\u6ce8\u91ca\u53ef\u4ee5\u663e\u8457\u51cf\u5c11\u4ee3\u7801\u4f53\u79ef\u3002 3. \u5408\u5e76\u91cd\u590d\u4ee3\u7801 \u627e\u51fa\u5e76\u5408\u5e76\u91cd\u590d\u7684\u4ee3\u7801\u5757\uff0c\u6d88\u9664\u5197\u4f59\u5e76\u51cf\u5c0f\u6587\u4ef6\u5927\u5c0f\u3002 4. \u79fb\u9664\u7a7a\u767d\u5b57\u7b26 \u989d\u5916\u7684\u7a7a\u683c\u3001\u6362\u884c\u7b26\u548c\u5236\u8868\u7b26\u53ef\u4ee5\u589e\u52a0\u6587\u4ef6\u5927\u5c0f\u3002\u79fb\u9664\u8fd9\u4e9b\u5b57\u7b26\u53ef\u4ee5\u7f29\u5c0f\u4ee3\u7801\u3002 5. \u4f18\u5316\u4ee3\u7801\u8def\u5f84 \u901a\u8fc7\u79fb\u9664\u672a\u4f7f\u7528\u7684\u4ee3\u7801\u548c\u4f18\u5316\u5206\u652f\u6761\u4ef6\uff0c\u53ef\u4ee5\u51cf\u5c11JavaScript \u8fd0\u884c\u65f6\u6267\u884c\u4e0d\u5fc5\u8981\u7684\u4ee3\u7801\u8def\u5f84\uff0c\u4ece\u800c\u7f29\u5c0f\u6587\u4ef6\u5927\u5c0f\u3002 \u538b\u7f29\u5de5\u5177 YUI Compressor UglifyJS Closure Compiler Webpack (\u5e26 Terser \u63d2\u4ef6) Babel (\u5e26 terser presets) \u6700\u4f73\u5b9e\u8df5 \u542f\u7528\u538b\u7f29\u9009\u9879\u4f5c\u4e3a\u5f00\u53d1\u5de5\u5177\u7684\u4e00\u90e8\u5206\u3002 \u4f7f\u7528\u57fa\u4e8e Web \u7684\u670d\u52a1\u6216\u547d\u4ee4\u884c\u5de5\u5177\u6765\u6267\u884c\u538b\u7f29\u3002 \u6d4b\u8bd5\u538b\u7f29\u540e\u4ee3\u7801\u7684\u5b8c\u6574\u6027\uff0c\u4ee5\u786e\u4fdd\u6ca1\u6709\u5f15\u5165\u4efb\u4f55\u9519\u8bef\u3002 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-3250","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3250","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=3250"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/3250\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=3250"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=3250"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=3250"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}