{"id":76,"date":"2022-05-29T14:56:22","date_gmt":"2022-05-29T06:56:22","guid":{"rendered":"http:\/\/www.33weixin.com\/index\/?p=76"},"modified":"2022-05-29T15:00:33","modified_gmt":"2022-05-29T07:00:33","slug":"%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e9%83%a8%e7%bd%b2","status":"publish","type":"post","link":"http:\/\/www.33weixin.com\/index\/index.php\/2022\/05\/29\/%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e9%83%a8%e7%bd%b2\/","title":{"rendered":"\u751f\u4ea7\u73af\u5883\u90e8\u7f72"},"content":{"rendered":"<h2 id=\"\u5220\u9664\u8b66\u544a\">\u5220\u9664\u8b66\u544a<\/h2>\n<p>\u4e3a\u4e86\u51cf\u5c11\u6587\u4ef6\u5927\u5c0f\uff0cVue \u7cbe\u7b80\u72ec\u7acb\u7248\u672c\u5df2\u7ecf\u5220\u9664\u4e86\u6240\u6709\u8b66\u544a\uff0c\u4f46\u662f\u5f53\u4f60\u4f7f\u7528 Webpack \u6216 Browserify \u7b49\u5de5\u5177\u65f6\uff0c\u4f60\u9700\u8981\u4e00\u4e9b\u989d\u5916\u7684\u914d\u7f6e\u5b9e\u73b0\u8fd9\u70b9\u3002<\/p>\n<h3 id=\"webpack\">Webpack<\/h3>\n<p>\u4f7f\u7528 Webpack \u7684\u00a0<a href=\"http:\/\/webpack.github.io\/docs\/list-of-plugins.html#defineplugin\" target=\"_blank\" rel=\"noopener\">DefinePlugin<\/a>\u00a0\u6765\u6307\u5b9a\u751f\u4ea7\u73af\u5883\uff0c\u4ee5\u4fbf\u5728\u538b\u7f29\u65f6\u53ef\u4ee5\u8ba9 UglifyJS \u81ea\u52a8\u5220\u9664\u4ee3\u7801\u5757\u5185\u7684\u8b66\u544a\u8bed\u53e5\u3002\u4f8b\u5982\u914d\u7f6e\uff1a<\/p>\n<pre><code class=\"lang-js\"><span class=\"hljs-keyword\">var<\/span> webpack = <span class=\"hljs-built_in\">require<\/span>(<span class=\"hljs-string\">'webpack'<\/span>)\n\n<span class=\"hljs-built_in\">module<\/span>.exports = {\n  <span class=\"hljs-comment\">\/\/ ...<\/span>\n  plugins: [\n    <span class=\"hljs-comment\">\/\/ ...<\/span>\n    <span class=\"hljs-keyword\">new<\/span> webpack.DefinePlugin({\n      <span class=\"hljs-string\">'process.env'<\/span>: {\n        NODE_ENV: <span class=\"hljs-string\">'\"production\"'<\/span>\n      }\n    }),\n    <span class=\"hljs-keyword\">new<\/span> webpack.optimize.UglifyJsPlugin({\n      compress: {\n        warnings: <span class=\"hljs-literal\">false<\/span>\n      }\n    })\n  ]\n}\n<\/code><\/pre>\n<h3 id=\"browserify\">Browserify<\/h3>\n<ul>\n<li>\u8fd0\u884c\u6253\u5305\u547d\u4ee4\uff0c\u8bbe\u7f6e\u00a0<code>NODE_ENV<\/code>\u00a0\u4e3a\u00a0<code>\"production\"<\/code>\u3002\u7b49\u4e8e\u544a\u8bc9\u00a0<code>vueify<\/code>\u00a0\u907f\u514d\u5f15\u5165\u70ed\u91cd\u8f7d\u548c\u5f00\u53d1\u76f8\u5173\u4ee3\u7801\u3002<\/li>\n<li>\u4f7f\u7528\u4e00\u4e2a\u5168\u5c40\u00a0<a href=\"https:\/\/github.com\/hughsk\/envify\" target=\"_blank\" rel=\"noopener\">envify<\/a>\u00a0\u8f6c\u6362\u4f60\u7684 bundle \u6587\u4ef6\u3002\u8fd9\u53ef\u4ee5\u7cbe\u7b80\u6389\u5305\u542b\u5728 Vue \u6e90\u7801\u4e2d\u6240\u6709\u73af\u5883\u53d8\u91cf\u6761\u4ef6\u76f8\u5173\u4ee3\u7801\u5757\u5185\u7684\u8b66\u544a\u8bed\u53e5\u3002\u4f8b\u5982\uff1a<\/li>\n<\/ul>\n<pre><code class=\"lang-bash\">NODE_ENV=production browserify -g envify <span class=\"hljs-_\">-e<\/span> main.js | uglifyjs -c -m &gt; build.js\n<\/code><\/pre>\n<ul>\n<li>\u4f7f\u7528 vueify \u4e2d\u5305\u542b\u7684 extract-css \u63d2\u4ef6\uff0c\u63d0\u53d6\u6837\u5f0f\u5230\u5355\u72ec\u7684css\u6587\u4ef6\u3002<\/li>\n<\/ul>\n<pre><code class=\"lang-bash\">NODE_ENV=production browserify -g envify -p [ vueify\/plugins\/extract-css -o build.css ] <span class=\"hljs-_\">-e<\/span> main.js | uglifyjs -c -m &gt; build.js\n<\/code><\/pre>\n<h2 id=\"\u8ddf\u8e2a\u8fd0\u884c\u65f6\u9519\u8bef\">\u8ddf\u8e2a\u8fd0\u884c\u65f6\u9519\u8bef<\/h2>\n<p>\u5982\u679c\u5728\u7ec4\u4ef6\u6e32\u67d3\u65f6\u51fa\u73b0\u8fd0\u884c\u9519\u8bef\uff0c\u9519\u8bef\u5c06\u4f1a\u88ab\u4f20\u9012\u81f3\u5168\u5c40\u00a0<code>Vue.config.errorHandler<\/code>\u00a0\u914d\u7f6e\u51fd\u6570\uff08\u5982\u679c\u5df2\u8bbe\u7f6e\uff09\u3002\u5229\u7528\u8fd9\u4e2a\u94a9\u5b50\u51fd\u6570\u548c\u9519\u8bef\u8ddf\u8e2a\u670d\u52a1\uff08\u5982\u00a0<a href=\"https:\/\/sentry.io\/\" target=\"_blank\" rel=\"noopener\">Sentry<\/a>\uff0c\u5b83\u4e3a Vue \u63d0\u4f9b<a href=\"https:\/\/sentry.io\/for\/vue\/\" target=\"_blank\" rel=\"noopener\">\u5b98\u65b9\u96c6\u6210<\/a>\uff09\uff0c\u53ef\u80fd\u662f\u4e2a\u4e0d\u9519\u7684\u4e3b\u610f\u3002<\/p>\n<h2 id=\"\u63d0\u53d6-css\">\u63d0\u53d6 CSS<\/h2>\n<p>\u4f7f\u7528<a href=\"http:\/\/caibaojian.com\/vue\/guide\/single-file-components.html\">\u5355\u6587\u4ef6\u7ec4\u4ef6<\/a>\u65f6\uff0c<code>&lt;style&gt;<\/code>\u00a0\u6807\u7b7e\u5728\u5f00\u53d1\u8fd0\u884c\u8fc7\u7a0b\u4e2d\u4f1a\u88ab\u52a8\u6001\u5b9e\u65f6\u6ce8\u5165\u3002\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u4ece\u6240\u6709\u7ec4\u4ef6\u4e2d\u63d0\u53d6\u6837\u5f0f\u5230\u5355\u72ec\u7684 CSS \u6587\u4ef6\u4e2d\u3002\u6709\u5173\u5982\u4f55\u5b9e\u73b0\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u67e5\u9605\u00a0<a href=\"http:\/\/vue-loader.vuejs.org\/en\/configurations\/extract-css.html\" target=\"_blank\" rel=\"noopener\">vue-loader<\/a>\u00a0\u548c\u00a0<a href=\"https:\/\/github.com\/vuejs\/vueify#css-extraction\" target=\"_blank\" rel=\"noopener\">vueify<\/a>\u00a0\u76f8\u5e94\u6587\u6863\u3002<\/p>\n<p><code>vue-cli<\/code>\u00a0\u5df2\u7ecf\u914d\u7f6e\u597d\u4e86\u5b98\u65b9\u7684\u00a0<code>webpack<\/code>\u00a0\u6a21\u677f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5220\u9664\u8b66\u544a \u4e3a\u4e86\u51cf\u5c11\u6587\u4ef6\u5927\u5c0f\uff0cVue \u7cbe\u7b80\u72ec\u7acb\u7248\u672c\u5df2\u7ecf\u5220\u9664\u4e86\u6240\u6709\u8b66\u544a\uff0c\u4f46\u662f\u5f53\u4f60\u4f7f\u7528 Webpack \u6216 Brow&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/posts\/76"}],"collection":[{"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/comments?post=76"}],"version-history":[{"count":1,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/posts\/76\/revisions"}],"predecessor-version":[{"id":77,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/posts\/76\/revisions\/77"}],"wp:attachment":[{"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/media?parent=76"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/categories?post=76"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.33weixin.com\/index\/index.php\/wp-json\/wp\/v2\/tags?post=76"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}