{"id":254243,"date":"2022-10-11T10:09:52","date_gmt":"2022-10-11T02:09:52","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=254243"},"modified":"2022-10-04T11:12:05","modified_gmt":"2022-10-04T03:12:05","slug":"vite-or-vue-cli","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/vite-or-vue-cli.html","title":{"rendered":"Vite\u6216Vue CLI\u6765\u9009\u4e00\u4e2a\u6700\u9002\u5408\u4f60\u7684"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8 Vite \u4e0e Vue CLI\uff0c\u4ee5\u4fbf\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u505a\u51fa\u6700\u4f73\u9009\u62e9\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u968f\u7740 Vue \u751f\u6001\u7cfb\u7edf\u7684\u6210\u719f\uff0c\u5df2\u7ecf\u5f15\u5165\u4e86\u8bb8\u591a\u65b0\u6280\u672f\u3002\u867d\u7136\u4e00\u4e9b\u5f00\u53d1\u4eba\u5458\u53ef\u80fd\u4ece\u4e00\u4e2a\u666e\u901a\u7684 JavaScript \u6587\u4ef6\u5f00\u59cb\uff0c\u5e76\u5728\u9875\u9762\u4e2d\u5305\u542b Vue\u3002\u4f46\u968f\u7740\u65f6\u95f4\u7684\u63a8\u79fb\uff0c\u5728\u5f00\u53d1 Vue \u5e94\u7528\u7a0b\u5e8f\u65f6\uff0c\u4f7f\u7528\u6253\u5305\u5de5\u5177\u548c\u547d\u4ee4\u884c\u754c\u9762\u6210\u4e3a\u66f4\u52a0\u6807\u51c6\u7684\u5f00\u53d1\u6d41\u7a0b\u3002<\/p>\n

Vue \u4e0d\u4f1a\u5f3a\u5236\u4f60\u9009\u62e9\u67d0\u79cd\u5f00\u53d1\u3001\u6253\u5305\u65b9\u5f0f\uff0c\u4f46vue\u7684\u751f\u6001\u7cfb\u7edf\u63d0\u4f9b\u4e86\u8bb8\u591a\u5de5\u5177\uff0c\u4f8b\u5982 Vue CLI \u548c\u6700\u8fd1\u7684\u63a8\u51fa\u7684Vite js\u3002\u90a3\u4e48\u4f60\u5e94\u8be5\u4f7f\u7528 Vite \u8fd8\u662f Vue CLI\uff1f\u5728\u505a\u51fa\u9009\u62e9\u7684\u65f6\u5019\uff0c\u4e86\u89e3 Vite \u548c Vue CLI \u4e4b\u95f4\u7684\u533a\u522b\u4f1a\u5bf9\u6211\u4eec\u6709\u5f88\u5927\u7684\u5e2e\u52a9\u3002<\/p>\n

\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u5c06\u6df1\u5165\u63a2\u8ba8 Vite \u4e0e Vue CLI\uff0c\u4ee5\u4fbf\u4f60\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u505a\u51fa\u6700\u4f73\u9009\u62e9\u3002<\/p>\n

Vue CLI \u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff1f<\/strong><\/div>\n

Vue \u547d\u4ee4\u884c\u754c\u9762 (CLI) \u56f4\u7ed5 Webpack \u521b\u5efa\u4e00\u4e2a\u5305\u88c5\u5668\u6765\u7f16\u8bd1\u4f60\u7684 Vue \u9879\u76ee\u3002\u4f46\u662f\u6211\u4eec\u4e3a\u4ec0\u4e48\u8981\u7f16\u8bd1\u5b83\u5462\uff1f\u5728 Webpack \u548c Rollup \u8fd9\u6837\u7684\u6253\u5305\u5de5\u5177\u51fa\u73b0\u4e4b\u524d\uff0c\u6211\u4eec\u53ea\u9700\u8981\u5c06\u6211\u4eec\u7684 JavaScript \u6587\u4ef6\u90e8\u7f72\u5230\u670d\u52a1\u5668\u5e76\u5c06\u5b83\u4eec\u5168\u90e8\u5305\u542b\u5728\u4e00\u4e2a\u9875\u9762\u4e0a\u3002\u5f53\u6211\u4eec\u7684\u9879\u76ee\u5f88\u5c0f\u7684\u65f6\u5019\uff0c\u8fd9\u79cd\u6548\u679c\u5f88\u597d\u3002\u4f46\u662f\u968f\u7740 Vue \u7684\u53d1\u5c55\uff0c\u6211\u4eec\u5f00\u59cb\u9700\u8981\u67d0\u79cd\u7a0b\u5ea6\u7684\u6253\u5305\u529f\u80fd\u3002\u5355\u6587\u4ef6\u7ec4\u4ef6 (SFC) \u548c TypeScript\u7684\u4f7f\u7528\u90fd\u9700\u8981\u501f\u52a9\u6253\u5305\u5de5\u5177\u6765\u6784\u5efa\u6211\u4eec\u7684\u9879\u76ee\u3002\u8fd9\u5c31\u662f\u4e3a\u4ec0\u4e48\u8981\u5f15\u5165Vue CLI \u3002<\/p>\n

Vue CLI \u5141\u8bb8\u6211\u4eec\u5728\u5f00\u53d1\u548c\u751f\u4ea7\u671f\u95f4\u521b\u5efa\u548c\u6784\u5efa\u9879\u76ee\u3002CLI \u9690\u85cf\u4e86 Webpack \u7684\u590d\u6742\u914d\u7f6e\u7ec6\u8282\uff0c\u5e76\u5728\u5f00\u53d1\u548c\u751f\u4ea7\u8fc7\u7a0b\u4e2d\u4e3a\u6211\u4eec\u7684\u9879\u76ee\u63d0\u4f9b\u670d\u52a1\u3002\u4f46\u662f\uff0c\u5982\u679c\u6211\u4eec\u60f3\u8981\u5c06\u5b83\u4e0e Vite \u8fdb\u884c\u6bd4\u8f83\uff0c\u90a3\u5c31\u8ba9\u6211\u4eec\u518d\u6df1\u5165\u4e00\u70b9\u3002<\/p>\n

Webpack<\/strong><\/span><\/div>\n

\u6b63\u5982 Webpack \u7f51\u7ad9\u6240\u63cf\u8ff0\u7684\uff0cWebpack \u662f\u4e00\u4e2a\u9759\u6001\u6a21\u5757\u6253\u5305\u5de5\u5177\u3002\u4f46\u662f\uff0c\u8fd9\u662f\u4ec0\u4e48\u610f\u601d\uff1fWebpack \u7684\u4e3b\u8981\u76ee\u6807\u662f\u83b7\u53d6\u4f60\u7684 Web \u9879\u76ee\u7684\u8d44\u4ea7\u5e76\u5c06\u5b83\u4eec\u6253\u5305\u5230\u5c11\u91cf\u6587\u4ef6\u4e2d\u4ee5\u4f9b\u6d4f\u89c8\u5668\u4e0b\u8f7d\u3002\u8fd9\u5e76\u4e0d\u610f\u5473\u7740\u7acb\u5373\u52a0\u8f7d\u9879\u76ee\u7684\u6240\u6709\u6587\u4ef6\uff0c\u4e5f\u53ef\u4ee5\u6309\u9700\u4e0b\u8f7d\u3002<\/p>\n

\u867d\u7136 Webpack \u53ef\u4ee5\u6253\u5305\u975e\u4ee3\u7801\u8d44\u4ea7\uff0c\u4f46\u5b83\u771f\u6b63\u7684\u95ea\u5149\u70b9\u662f\u6253\u5305\u76f8\u5173\u7684\u4ee3\u7801\u3002\u4f60\u53ef\u4ee5\u8ba4\u4e3a\u6253\u5305\u5c31\u662f\u7b80\u5355\u5730\u5c06\u6240\u6709\u4ee3\u7801\u6587\u4ef6\uff08\u4f8b\u5982JavaScript\/TypeScript\uff09\u5408\u5e76\u5728\u4e00\u8d77\uff0c\u4f46\u5b9e\u9645\u4e0a\u8fd9\u91cc\u8fd8\u6709\u66f4\u591a\u7684\u5185\u5bb9\u3002<\/p>\n

Webpack \u5904\u7406\u4ee3\u7801\u4e2d\u7684 imports\/require \u8bed\u53e5\u65f6\uff0c\u53ea\u5305\u542b\u5b9e\u9645\u9700\u8981\u7684\u6587\u4ef6\u3002\u6b64\u5916\uff0c\u5b83\u7ecf\u5e38\u8fdb\u884c\u201ctree-shaking\u201d\uff0c\u8fd9\u53ef\u4ee5\u5220\u9664\u5b9e\u9645\u4e0a\u4ece\u672a\u5f15\u7528\u8fc7\u7684\u4ee3\u7801\u5757\uff08\u4f8b\u5982\u7c7b\u3001\u51fd\u6570\uff09\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0cWebpack \u53ef\u4ee5\u975e\u5e38\u9ad8\u6548\u5730\u6253\u5305\u4f60\u7684\u9879\u76ee\u3002\u4f46\u662f\uff0c\u5982\u679c\u6211\u4eec\u6b63\u5728\u7814\u7a76 Vue CLI\uff08\u5305\u542b Webpack\uff09\u4e0e Vite \u7684\u6bd4\u8f83\uff0c\u6211\u4eec\u9700\u8981\u7ee7\u7eed\u770b\u770b\u5728\u5f00\u53d1\u65f6\u4f1a\u53d1\u751f\u4ec0\u4e48\u3002<\/p>\n

\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u7684 Webpack<\/strong><\/span><\/div>\n

\u5728 Vue CLI \u4e2d\uff0cWebpack \u7528\u4e8e\u6a21\u5757\u7ed1\u5b9a\u3002\u5728\u5f00\u53d1\u65f6\u4e5f\u4f1a\u53d1\u751f\u8fd9\u79cd\u7ed1\u5b9a\u3002\u5f53\u4f60\u901a\u8fc7 CLI \u5f00\u53d1 Vue \u9879\u76ee\u65f6\uff0c\u5b83\u4f1a\u6307\u793a Webpack \u4ee5\u589e\u91cf\u65b9\u5f0f\u6784\u5efa\u9879\u76ee\u5e76\u76d1\u542c\u66f4\u6539\uff0c\u4ee5\u4fbf\u5b83\u53ef\u4ee5\u5c06\u66f4\u6539\u7684\u6587\u4ef6\u6253\u5305\u5e76\u5728\u6d4f\u89c8\u5668\u4e2d\u8fdb\u884c\u66ff\u6362\u3002\u56e0\u4e3a\u6784\u5efa\u5305\u662f\u589e\u91cf\u7684\uff0c\u6240\u4ee5\u5b83\u53ef\u4ee5\u5728\u4f60\u5f00\u53d1\u9879\u76ee\u65f6\u5feb\u901f\u7684\u5c06\u66f4\u6539\u540c\u6b65\u3002\u7b2c\u4e00\u6b21\u6784\u5efa\u9879\u76ee\u65f6\u53ef\u80fd\u4f1a\u8f83\u6162\uff08\u5373 3 \u79d2\u6216\u66f4\u957f\u65f6\u95f4\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u4f60\u7684\u9879\u76ee\u5927\u5c0f\uff09\uff0c\u4f46\u4e00\u65e6\u9879\u76ee\u542f\u52a8\uff0c\u589e\u91cf\u66f4\u6539\u7684\u540c\u6b65\u4f1a\u975e\u5e38\u5feb\uff08\u5373 < 1 \u79d2\uff0c\u901a\u5e38\u5c0f\u4e8e 100 \u6beb\u79d2\uff09\u3002\n\n[yiji]Vite js \u662f\u5982\u4f55\u5de5\u4f5c\u7684\uff1f[\/yiji]\n\u5982\u679c\u4f60\u662fVite\u7684\u65b0\u624b\uff0c\u6211\u5efa\u8bae\u76f4\u63a5\u4ece\u5b83\u7684\u521b\u9020\u8005\u5c24\u96e8\u6eaa\u90a3\u91cc\u5b66\u4e60\uff0c\u4ed6\u5728Vue Mastery\u7684\u8bfe\u7a0b\u201c\u4f7f\u7528vite\u5feb\u901f\u6784\u5efa\u201d\u4e2d\u6559\u6211\u4eec\u5173\u4e8eVite\u7684\u77e5\u8bc6\u3002\n\n\u5982\u679c\u4f60\u770b\u8fc7\u8be5\u8bfe\u7a0b\u7684\u7b2c\u4e00\u8bfe\uff08\u5b83\u662f\u514d\u8d39\u7684\uff09\uff0c\u4f60\u5c06\u4e86\u89e3\u5982\u4f55\u5f00\u59cb\uff0c\u4f46\u5728\u6211\u4eec\u5c06\u5176\u4e0e Vue CLI \u548c Webpack \u8fdb\u884c\u6bd4\u8f83\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u4e86\u89e3 Vite \u7684\u5de5\u4f5c\u539f\u7406\u3002\n\n\u5f53\u4f60\u521b\u5efa\u4e00\u4e2a\u57fa\u672c\u7684 Vite \u9879\u76ee\uff08\u5728\u6211\u4eec\u7684\u4f8b\u5b50\u4e2d\uff0c\u662f Vue 3 \u7684 Vite \u9879\u76ee\uff09\u65f6\uff0cindex.html\u6587\u4ef6\u662f\u975e\u5e38\u57fa\u672c\u7684\uff1a\n\n[erji]index.html[\/erji]\n\n\"\"
\n\u4f60\u4f1a\u6ce8\u610f\u5230\u8fd9\u4e0e Vue CLI \u770b\u8d77\u6765\u5f88\u76f8\u4f3c\uff0c\u4f46\u6709\u4e00\u4e2a\u4e3b\u8981\u4f8b\u5916\uff1ascript\u6807\u8bb0\u4f7f\u7528type=\"module\u201c\u3002\u9664\u975e\u4f60\u4f7f\u7528 TypeScript\uff0c\u5426\u5219\u8fd9\u91cc\u6ca1\u6709\u771f\u6b63\u7684\u6784\u5efa\u6b65\u9aa4\u3002src\u811a\u672c\u6307\u5411\u4f60\u7684\u5b9e\u9645\u6e90\u4ee3\u7801\u6587\u4ef6\u3002<\/p>\n

\u5f53\u8fd9\u4e2a\u8bf7\u6c42\u4f20\u5165\u65f6\uff0c\u5b83\u4f1a\u5c06main.js\u6587\u4ef6\u4f5c\u4e3a\u539f\u751f ES \u6a21\u5757\u53d1\u9001\u5230\u6d4f\u89c8\u5668\u3002\u8fd9\u610f\u5473\u7740\u5b83\u6839\u672c\u4e0d\u4f1a\u6253\u5305\u4f60\u7684\u4ee3\u7801\u3002\u5b9e\u9645\u4e0a\uff0c\u6e90\u6587\u4ef6\u53ea\u662f\u4e00\u4e2a\u7b80\u5355\u7684Vue\u542f\u52a8\u6587\u4ef6\uff1a<\/p>\n

main.js<\/strong><\/span><\/div>\n

\"\"<\/p>\n

\u8fd9\u91cc\u53d1\u751f\u4e86\u4ec0\u4e48\uff1fVite \u6b63\u5728\u5229\u7528\u539f\u751f ES \u6a21\u5757\u548c\u52a8\u6001 ESM \u6a21\u5757\uff0c\u4ee5\u4fbf\u6839\u636e\u9700\u8981\u5c06\u4ee3\u7801\u6ce8\u5165\u6d4f\u89c8\u5668\u3002\u672c\u8d28\u4e0a\uff0c\u9879\u76ee\u4e2d\u7684\u6bcf\u6b21\u5bfc\u5165\u90fd\u4f1a\u5f3a\u5236\u6d4f\u89c8\u5668\u6839\u636e\u9700\u8981\u52a0\u8f7d\u6bcf\u4e2a\u6709\u6548\u8d1f\u8f7d\u3002\u8fd9\u4e9b\u5bfc\u5165\u5c06\u7ea7\u8054\u4ee5\u83b7\u5f97\u7279\u5b9a\u60c5\u51b5\u4e0b\u6240\u9700\u7684\u6240\u6709\u4ee3\u7801\u3002<\/p>\n

\u8fd9\u610f\u5473\u7740\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c Vite \u4e0d\u4f46\u4e3a\u4f60\u7684\u7f51\u7ad9\u63d0\u4f9b\u670d\u52a1\uff0c\u5e76\u4e14\u5b83\u4e5f\u652f\u6301\u52a8\u6001\u52a0\u8f7d\uff08\u5728\u652f\u6301\u5b83\u7684\u65b0\u6d4f\u89c8\u5668\u4e2d\uff0c\u5e76\u4e14\u4e5f\u517c\u5bb9\u65e7\u6d4f\u89c8\u5668\uff09\u3002<\/p>\n

\u6b64\u5916\uff0cVite \u5728\u4f60\u5f00\u53d1\u9879\u76ee\u65f6\u4f7f\u7528\u6a21\u5757\u70ed\u66ff\u6362 (HMR) \u6765\u66f4\u65b0\u4fee\u6539\u7684\u4ee3\u7801\u3002\u4f7f\u4f60\u80fd\u591f\u5728\u5f00\u53d1\u65f6\u83b7\u5f97\u5373\u65f6\u7684\u542f\u52a8\u901f\u5ea6\uff0c\u8fd9\u4f1a\u5927\u5927\u63d0\u9ad8\u5f00\u53d1\u4f53\u9a8c\u3002<\/p>\n

\u4f46\u662f Vite \u662f\u5982\u4f55\u5728\u751f\u4ea7\u73af\u5883\u4e2d\u5b9e\u73b0\u8fd9\u4e00\u70b9\u7684\u5462\uff1f\u8ba9\u6211\u4eec\u6765\u770b\u770b\u3002<\/p>\n

Vite \u548c\u751f\u4ea7\u73af\u5883<\/strong><\/div>\n

\u867d\u7136 Vite \u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u4f7f\u7528\u5176\u63d0\u4f9b\u6587\u4ef6\u7684\u80fd\u529b\u6765\u52a0\u901f\u8be5\u8fc7\u7a0b\uff0c\u4f46 Vite \u672c\u8eab\u5e76\u6ca1\u6709\u771f\u6b63\u6253\u5305\u4f60\u7684\u9879\u76ee\u3002\u76f8\u53cd\uff0c\u5b83\u4f9d\u8d56\u4e8e\u4e00\u4e2a\u540d\u4e3a\"Rollup\"\u7684\u6253\u5305\u7a0b\u5e8f\u6765\u8fdb\u884c\u5b9e\u9645\u7684\u6253\u5305\u3002<\/p>\n

\u901a\u8fc7\u4f7f\u7528Vite\u4e2d\u7684build\u547d\u4ee4\uff0c\u5b83\u5c06\u4f7f\u7528rollup\u6765\u6784\u5efa\u4f60\u7684\u9879\u76ee\uff1a<\/p>\n

\u547d\u4ee4\u884c<\/strong><\/span><\/div>\n
\r\n> vite build\r\n<\/pre>\n

\u8fd9\u5c06\u6784\u5efa\u9879\u76ee\uff0c\u751f\u6210\u51e0\u4e2a\u6587\u4ef6\uff08\u4f7f\u7528\u6821\u9a8c\u548c\u4ee5\u907f\u514d\u7f13\u5b58\u7684\u5f71\u54cd\uff09\uff1a<\/p>\n

\u547d\u4ee4\u884c<\/strong><\/span><\/div>\n

\"\"<\/p>\n

\u4e0e Vue CLI \u975e\u5e38\u76f8\u4f3c\uff0cVite \u5141\u8bb8\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u914d\u7f6e Rollup\uff08\u914d\u7f6e\u6587\u4ef6\u5177\u6709\u975e\u5e38\u5408\u7406\u7684\u9ed8\u8ba4\u503c\uff09\uff1a<\/p>\n

vue.config.js<\/strong><\/span><\/div>\n

\"\"<\/p>\n

\u4f8b\u5982\uff0c\u8bbe\u7f6esourcemap\u548coutDir\uff0c\u90fd\u76f4\u63a5\u4f20\u9012\u7ed9 Rollup \u8fdb\u884c\u914d\u7f6e\u3002vite.config.js\u4e2d\u7684\u9009\u9879\u5141\u8bb8\u4f60\u5728\u5fc5\u8981\u65f6\u5bf9Rollup\u8fdb\u884c\u6df1\u5165\u914d\u7f6e\u3002<\/p>\n

\u56e0\u6b64\uff0c\u4f7f\u7528 Vite \u5b9e\u9645\u4e0a\u4e3a\u4f60\u63d0\u4f9b\u4e86\u4e24\u79cd\u4e0d\u540c\u7684\u4f53\u9a8c\uff1a\u5728\u5f00\u53d1\u65f6\u7684\u5feb\u901f\u8c03\u8bd5\u4f53\u9a8c\uff1b\u9075\u5faa Rollup \u89c4\u8303\uff0c\u5141\u8bb8\u4f60\u4ee5\u60f3\u8981\u7684\u65b9\u5f0f\u6784\u5efa\u9879\u76ee\u3002<\/p>\n

\u5f53 Vite \u4f7f\u7528Rollup\u65f6\uff0c Rollup\u4e0d\u662f\u5fc5\u9700\u7684\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u4f60\u60f3\u8981\u7684\u6253\u5305\u5de5\u5177\u4ee3\u66ff Rollup \u6765\u6784\u5efa\u4f60\u7684 Vue \u9879\u76ee\u3002<\/p>\n

Vite \u6216 Vue CLI\uff1a\u6211\u5e94\u8be5\u9009\u62e9\u54ea\u4e2a\uff1f<\/strong><\/div>\n

\u8fd9\u4e2a\u95ee\u9898\u6ca1\u6709\u4e00\u4e2a\u660e\u786e\u7684\u7b54\u6848\uff0cVite \u8fd8\u662f Vue CLI \u54ea\u4e2a\u66f4\u597d\uff1f<\/p>\n

\u4f46\u6211\u60f3\u628a\u5b83\u5206\u6210\u4e24\u4e2a\u4e0d\u540c\u7684\u8ba8\u8bba\uff1a\u5728\u5f00\u53d1\u4e2d\u4f7f\u7528\u548c\u5728\u751f\u4ea7\u4e2d\u4f7f\u7528\u3002<\/p>\n

\u5f00\u53d1\u65f6<\/strong><\/span><\/div>\n

Vue CLI\uff08\u4ee5\u53ca\u6269\u5c55\u7684 Webpack\uff09\u548c Vite \u7684\u6574\u4f53\u4f53\u9a8c\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u53ef\u80fd\u662f\u76f8\u4f3c\u7684\u3002\u4e24\u8005\u90fd\u589e\u91cf\u6784\u5efa\u4f60\u7684\u9879\u76ee\u5e76\u4f7f\u7528\u6a21\u5757\u70ed\u66ff\u6362\u6765\u66ff\u6362\u8fd0\u884c\u7684\u9879\u76ee\u4e2d\u6539\u52a8\u7684\u4ee3\u7801\u3002<\/p>\n

\u4e24\u8005\u7684\u533a\u522b\u5f52\u7ed3\u4e3a\u901f\u5ea6\u3002Webpack \u4ece\u6e90\u4ee3\u7801\u6784\u5efa\u9879\u76ee\uff0c\u5e76\u5728\u5f00\u53d1\u9879\u76ee\u65f6\u6301\u7eed\u8fdb\u884c\u589e\u91cf\u6784\u5efa\u3002<\/p>\n

\u53e6\u4e00\u65b9\u9762\uff0cVite \u4f1a\u6839\u636e\u9700\u8981\u5c06\u5b9e\u9645\u4ee3\u7801\u52a0\u8f7d\u5230\u6d4f\u89c8\u5668\u4e2d\u3002\u8fd9\u610f\u5473\u7740\u4e0d\u9700\u8981\u592a\u591a\u6e90\u4ee3\u7801\u7684\u6620\u5c04\uff0c\u56e0\u4e3a\u5728\u6d4f\u89c8\u5668\u4e2d\u8fd0\u884c\u7684\u4ee3\u7801\u5c31\u662f\u4f60\u6b63\u5728\u4f7f\u7528\u7684\u5b9e\u9645\u4ee3\u7801\uff08\u548c\u6587\u4ef6\uff09\u3002\u8fd9\u610f\u5473\u7740\uff0c\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u4f60\u4f1a\u53d1\u73b0 Vite \u6bd4 Vue CLI \u63d0\u4f9b\u66f4\u5feb\u901f\u548c\u76f4\u63a5\u7684\u5f00\u53d1\u548c\u8c03\u8bd5\u4f53\u9a8c\u3002\u5728 Vue CLI \u4e2d\uff0c\u4f60\u8c03\u8bd5\u7684\u662fWebpack \u751f\u6210\u7684\u4ee3\u7801\uff08\u901a\u8fc7\u4f7f\u7528\u6e90\u4ee3\u7801\u6620\u5c04\uff09\uff0c\u800c\u4e0d\u662f\u8c03\u8bd5\u7684\u4f60\u6b63\u5728\u7f16\u5199\u7684\u4ee3\u7801\u3002<\/p>\n

\u53e6\u4e00\u4e2a\u597d\u5904\u662f Vite \u4e0d\u4f9d\u8d56\u4e8e Vue.js\u3002Vite \u53ef\u4ee5\u5728\u4e0d\u540c\u7684\u73af\u5883\u4e2d\u4f7f\u7528\uff1a\u7eaf JavaScript\u3001React\u3001PReact \u548c SvelteKit\u3002\u56e0\u6b64\uff0c\u5982\u679c\u4f60\u5728\u591a\u4e2a\u73af\u5883\u4e2d\u5de5\u4f5c\uff0c\u5219\u53ef\u4ee5\u66f4\u8f7b\u677e\u5730\u4f7f\u7528\uff08\u548c\u914d\u7f6e\uff09\u4e00\u4e2a\u5de5\u5177\u6765\u5904\u7406\u4e0d\u540c\u7684\u9879\u76ee\u3002<\/p>\n

\u751f\u4ea7\u65f6<\/strong><\/span><\/div>\n

Rollup \u7c7b\u4f3c\u4e8e Webpack\uff08\u4ee5\u53caParcel\uff0c\u53e6\u4e00\u4e2a\u6d41\u884c\u7684\u6253\u5305\u5de5\u5177\uff09\uff0c\u5c3d\u7ba1\u5b83\u4eec\u7684\u5de5\u4f5c\u65b9\u5f0f\u6709\u70b9\u4e0d\u540c\u3002<\/p>\n

Webpack\u57fa\u4e8eCommonJS API\u6765\u7ba1\u7406JavaScript\u6a21\u5757\u3002\u5373\u4f7f Webpack \u652f\u6301 ES \u6a21\u5757\uff0c\u5e95\u5c42\u6784\u5efa\u7cfb\u7edf\u4ecd\u7136\u5e0c\u671b\u6a21\u5757\u53ef\u4ee5\u52a8\u6001\u52a0\u8f7d\uff08\u56e0\u4e3arequire()\u53ea\u6709\u5728\u51fd\u6570\u6267\u884c\u65f6\u624d\u5bfc\u5165\u6a21\u5757\uff09\u3002<\/p>\n

\u76f8\u6bd4\u4e4b\u4e0b\uff0cRollup \u4f9d\u8d56\u4e8e ES \u6a21\u5757\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u53ef\u4ee5\u6bd4 Webpack \u66f4\u8f7b\u677e\u5730\u8fdb\u884c\u9759\u6001\u5206\u6790\uff0c\u5c3d\u7ba1\u8fd9\u79cd\u5dee\u5f02\u975e\u5e38\u5c0f\u3002\u4f46\u662f\uff0c\u4f7f\u7528 Rollup \u9700\u8981\u4f60\u5177\u6709\u652f\u6301 ES \u6a21\u5757\u7684\u4f9d\u8d56\u9879\u3002\u8fd9\u53ef\u80fd\u4f1a\u7ed9\u4e0d\u652f\u6301ES\u6a21\u5757\u7684\u5e93\u5e26\u6765\u4e00\u4e9b\u95ee\u9898\uff0c\u4f46\u8fd9\u4e9b\u5e93\u73b0\u5728\u8d8a\u6765\u8d8a\u5c11\u4e86\u3002<\/p>\n

\u6700\u7ec8\uff0c\u7531\u4f60\u6765\u51b3\u5b9a<\/strong><\/div>\n

\u867d\u7136\u6211\u4e0d\u80fd\u4e3a\u4f60\u505a\u51b3\u5b9a\uff0c\u4f46\u6211\u5e0c\u671b\u6211\u5df2\u7ecf\u5217\u51fa\u4e86\u8fd9\u4e24\u79cd\u65b9\u6cd5\u7684\u4f18\u7f3a\u70b9\u3002\u6211\u901a\u5e38\u5c06 Vite\uff08\u5e26\u6709 Rollup\uff09\u7528\u4e8e\u65b0\u9879\u76ee\uff0c\u4f46\u6211\u6ca1\u6709\u770b\u5230\u8db3\u591f\u7684\u597d\u5904\u6765\u5438\u5f15\u6211\u5c06\u73b0\u6709\u7684\u6240\u6709Vue CLI\u9879\u76ee\u8fc1\u79fb\u5230Vite\u3002<\/p>\n

\u5728\u67d0\u4e9b\u65f6\u5019\uff0c\u8fd9\u4e0d\u592a\u91cd\u8981\uff0c\u56e0\u4e3a\u5c24\u96e8\u6eaa\u66fe\u8868\u793a\uff0c\u5b83\u4eec\u4f1a\u5728\u67d0\u4e2a\u65f6\u523b\u8d8b\u4e8e\u4e00\u81f4\uff08\u4f8b\u5982\uff0c\u5728 CLI \u4e2d\u7528 Vite \u66ff\u6362 Webpack\uff09\u3002\u4f46\u5c31\u76ee\u524d\u800c\u8a00\uff0c\u8fd9\u8fd8\u6ca1\u6709\u53d1\u751f\uff0c\u4e24\u79cd\u65b9\u6cd5\u90fd\u5f97\u5230\u4e86\u5f88\u597d\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u968f\u7740 Vue \u751f\u6001\u7cfb\u7edf\u7684\u6210\u719f\uff0c\u5df2\u7ecf\u5f15\u5165\u4e86\u8bb8\u591a\u65b0\u6280\u672f\u3002\u867d\u7136\u4e00\u4e9b\u5f00\u53d1\u4eba\u5458\u53ef\u80fd\u4ece\u4e00\u4e2a\u666e\u901a\u7684 JavaScript \u6587 […]<\/p>\n","protected":false},"author":1898,"featured_media":254251,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[936],"class_list":["post-254243","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread","tag-vue"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/254243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1898"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=254243"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/254243\/revisions"}],"predecessor-version":[{"id":254252,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/254243\/revisions\/254252"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/254251"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=254243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=254243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=254243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}