create-react-app鍜?spa"/>

Posted 濂囪垶鍛ㄥ垔

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了相关的知识,希望对你有一定的参考价值。

缂栬€呮寜锛氭湰鏂囩敱chaussen鍦ㄤ紬鎴愮炕璇戝钩鍙颁笂缈昏瘧銆?/p>

璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?><em class=缁堢鐢婚潰锛屾紓浜殑webpack闈㈡澘

Webpack-dashboard鎻掍欢鍦℅ithub缃戠珯涓婃槦鏁拌秴杩?0000锛屼絾鎴戣繕鍑犱箮浠庢病纰拌繃銆傝繖涔堟鐨勬彃浠讹紝涓轰粈涔堜笉鍒╃敤璧锋潵鍛紵鐜板湪锛岀瀯鍑嗙殑灏辨槸浣犱咯锛?span class="mq-8">create-react-app鍜?span class="mq-10">vue-cli馃槉

璁颁綇锛岃鏄儗鍚庢湁浜哄伔鐪嬪埌杩欎釜鐢婚潰锛屽氨鍋囪鍦ㄤ负缇庡浗鍥藉鑸ぉ灞€NASA宸ヤ綔銆?/em>


浣跨敤webpack锛屽挨鍏舵槸杩愯webpack鐨勫紑鍙戣€呮湇鍔″櫒鏃讹紝浠ヤ笅鐢婚潰鍙兘澶у宸茬粡瑙佹儻浜嗐€?img src="/img?url=http://mmbiz.qpic.cn/mmbiz_png/d8tibSEfhMMp6UnsaKmhdHmQpuEnjicibredN60ePtzKvXtNByNcN7KA0HqtsFw832KmfSgPXbSW5W9yHnicoarlPg/0?wx_fmt=png" class="mq-16" data-ratio="0.7541478129713424" data-w="663" data-type="png" alt="璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?>

鎴戜滑閮界煡閬搘ebpack鐨勬棩蹇椾俊鎭湁澶氬ソ锛屼絾鎴戜篃鐨勭‘寰堝ソ濂囷紝杩欎竴灞忕殑淇℃伅鍒板簳鏄粰璋佺湅鐨勶紵杩滆秴浜虹被鐨勯珮绛夊鏄熺敓鐗╁悧锛?/p>

webpack鐨勬棩蹇椾俊鎭€ラ渶閰嶄竴涓弸濂界殑鐣岄潰銆?/p>


鏁戞槦鏉ヤ簡锛?span class="mq-21">Webpack-dashboard闈㈡澘

璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<p class=璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?><em class=鐪嬭捣鏉ュソ澶氫簡

璁╀汉璇昏捣鏉ユ槸涓嶆槸瀹规槗寰楀浜嗭紵


杩欎袱涓伐鍏烽兘鏄熀浜庢ā鏉挎瀯寤虹▼搴忕殑锛岄兘鏄渶鐑棬鐨勩€傝鎴戜滑鐪嬩竴涓嬪畠浠浣曚娇鐢╳ebpack鏃ュ織鍔熻兘鐨勶細

璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<p class=璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?><em class=create-react-app


璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<p class=璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?><em class=vue-cli


杩樹笉鍧忋€?Webpack鏃ュ織鍛婅瘔鎴戜滑缂栬瘧鎴愬姛涓庡惁锛屼互鍙妛ebpack鏈嶅姟鍣ㄧ洃鍚殑绔彛銆備絾鑲畾杩樻湁鏀硅繘鐨勪綑鍦帮紝鍝€曞彧鏄竴鐐圭偣銆?/p>


create-react-app鍜寁ue-cli涓殑閿欒澶勭悊

璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<p class=璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?> 绗竴涓細鈥?span class=React锛岀浜屼釜锛?span class="mq-50">Vue鈥?/p>

寰堝ソ锛佷竴鏈夊彞娉曢敊璇紝鎴戜滑灏辩珛鍒诲緱鍒伴€氱煡浜嗭紒


Create-react-app鍜寁ue-cli鐨勬渶缁堟垚鍝佽緭鍑?/h3>

璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<p class=璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<p class=涔熷緢濂斤紝娌′粈涔堝彲璇寸殑锛佽鎴戜滑璇曡瘯webpack闈㈡澘鍚с€?/p>


鑷畾涔夐厤缃笅闈㈡澘鐨勪娇鐢?/h3>

鍒皐ebpack搴撶殑杩欎釜椤甸潰涓婂幓锛屾妸鑷畾涔墂ebpack閰嶇疆鍏嬮殕涓嬫潵锛屽啀鎵惧埌绗簲绔狅紝骞跺畨瑁卬pm渚濆瓨鍏崇郴鍖呫€?/p>

git clone git@github.com:wesharehoodies/webpack-2.0-from-scratch.git && cd webpack-2.0-from-scratch && git checkout chapter-5 && npm i && npm run start

鎶婅繖涓懡浠ょ矘璐村埌缁堢涓?/p>

杩欓噷鐨勬寚瀵艰鏄庡叡鏈変簲涓珷鑺傦紝涓€姝ヤ竴姝ユ暀澶у濡備綍璁剧疆webpack閰嶇疆銆傚己鐑堟帹鑽愬ぇ瀹堕€氳锛?/span>

绮樿创濂藉懡浠わ紝鍐嶅姞涓婁竴鐐硅€愬績锛岀劧鍚庡簲璇ョ湅鍒颁笅闈㈢殑鐢婚潰銆?/p>

璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<p class=寰堝ソ锛佹鏄垜浠兂瑕佺殑銆傜幇鍦ㄥ姞涓婂彉鍖栵紒

鐢∟PM锛?npm install webpack-dashboard --save-dev

鐢╕ARN锛?yarn add webpack-dashboard

鍦?span class="mq-77">webpack.config.js閲岄渶瑕佸鍏ラ潰鏉挎彃浠讹紝骞剁敤new鍏抽敭璇嶈皟鐢ㄦ彃浠躲€傚氨鍍忚繖鏍凤細

璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<p class=璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<p class=鏈€鍚庯紝鏇存柊涓€涓?span class="mq-83">package.json鑴氭湰锛岀粨鏋滃涓嬶細

"scripts": {

    "build": "webpack --progress",

    "start": "webpack-dashboard -- webpack-dev-server -d --hot --config webpack.config.js --watch",

    "production": "NODE_ENV=production webpack -p"

  },

鐢?span class="mq-108">npm run start鍛戒护鍚姩webpack,鐒跺悗灏辫兘鐪嬪埌:

璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<p class=鍝囷紒澶浜嗭紒璺熶笉涓婄殑璇濓紝杩欓噷鏈夋簮浠g爜 鉂?/span>

椤哄甫涓€鎻愶紝鎴戜滑鐢ㄤ笉鐫€杩欎箞宸ㄥぇ鐨勯潰鏉裤€備笅闈㈣繖涓疄渚嬶紝鏄剧ず浜嗙獥鍙eぇ灏忕殑璋冩暣銆傛劅璋Term銆?/p>

璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<p class=馃憤


璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<h3 class=闈㈡澘鎻掍欢鍜孋reate-react-app

鍙儨鎴戜滑蹇呴』鎵ц寮瑰嚭鍙傛暟銆?/p>

npm i -g create-react-app && create-react-app react-webpack-dashboard && cd react-webpack-dashboard && npm run eject

璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?>鎴戜笉鏄緢鍠滄寮瑰嚭锛屼笉杩囪鏄湁鍏跺畠鏂规硶锛岃鍛婅瘔鎴戯紒 璁剧疆鏂规硶鍜岃嚜瀹氫箟閰嶇疆鐩稿悓銆?/p> 
<p class=鎵撳紑config/webpack.config.dev.js鏂囦欢锛屽姞鍏ラ潰鏉挎彃浠讹紝鍒繕浜嗚鍦?span class="mq-128">plugins: []鎻掍欢琛ㄩ儴鍒嗗寘鍚繖涓彃浠躲€傚彲浠ョ敤CTRL + F蹇嵎閿煡鎵炬彃浠惰〃閮ㄥ垎锛屽簲璇ュ湪绗?14琛屽乏鍙崇殑鍦版柟銆?/p>

璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<p class=璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<p class=鎵撳紑package.json鏂囦欢锛屾洿鏂颁竴涓嬪惎鍔ㄨ剼鏈紝濡備笅锛?/p>

"start": "webpack-dashboard -- node scripts/start.js",

濂戒簡锛岃娴嬭瘯浜? 杩愯涓嬮潰鐨勫懡浠?/p>

npm run start

璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<p class=璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?>鎴愪簡銆?/p> 
<hr class=

璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<h3 class=闈㈡澘鎻掍欢鍜孷ue-cli

npm i -g vue-cli && vue init webpack vue-webpack-dashboard && cd vue-webpack-dashboard && npm i --save-dev webpack-dashboard

Vue娌℃湁寮瑰嚭鐨勬蹇点€傛棦鐒舵病浠€涔堜唬浠凤紝灏变笉鐢ㄤ激鑴戠瓔浜嗐€?/p>

鎵撳紑build/webpack.dev.conf.js鈥婃枃浠讹紝鍔犲叆鎻掍欢(绗?琛?/em>)锛岃繕鏈?绗?3琛?/em>)涔熻鎻掑叆鎻掍欢銆?/p>

璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<p class=鏈€鍚庯紝鍒?span class="mq-176">package.json鏂囦欢閲岋紝淇敼寮€鍙戣剼鏈紝濡備笅锛?/p>

鈥渄ev鈥?span class="mq-180">: 鈥渨ebpack-dashboard 鈥?node build/dev-server.js鈥?span class="mq-185">,

娴嬭瘯锛?/p>

npm run start

璋佽Webpack鏃ュ織鍙湁澶栨槦浜鸿兘鐪嬫噦锛?></p> 
<p class=鎴愬姛銆?/p>


璋㈣阿鍏虫敞锛屼翰锛?/p>


濂囪垶鍛ㄥ垔

鈥斺€斺€?span class="mq-203">鈥斺€斺€斺€斺€斺€斺€斺€斺€斺€斺€斺€?/span>鈥斺€斺€?/span>

棰嗙暐鍓嶇鎶€鏈?闃呰濂囪垶鍛ㄥ垔


闀挎寜浜岀淮鐮侊紝鍏虫敞濂囪垶鍛ㄥ垔

鈻?/strong>


以上是关于的主要内容,如果未能解决你的问题,请参考以下文章

谷歌浏览器调试jsp 引入代码片段,如何调试代码片段中的js

片段和活动之间的核心区别是啥?哪些代码可以写成片段?

VSCode自定义代码片段——.vue文件的模板

VSCode自定义代码片段6——CSS选择器

VSCode自定义代码片段——声明函数

VSCode自定义代码片段8——声明函数

(c)2006-2024 SYSTEM All Rights Reserved IT常识