"/>

webpack 3 姝e紡鍙戝竷锛岃浣犳洿鈥滃揩鈥?/h1>

Posted 濂囪垶鍛ㄥ垔

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了webpack 3 姝e紡鍙戝竷锛岃浣犳洿鈥滃揩鈥?/h1>

相关的知识,希望对你有一定的参考价值。

缂栬€呮寜锛氭湰鏂囩敱sangle7鍦ㄤ紬鎴愮炕璇戝钩鍙颁笂缈昏瘧銆倃ebpack3姝e紡鍙戝竷浜嗭紝鐪嬬湅浣犱笉鑳介敊杩囩殑鏂扮壒鎬ф湁鍝簺銆?/span>

缁堜簬璧板埌杩欓噷锛屽お缇庝簡

馃嵕馃殌webpack 3 姝e紡鍙戝竷馃殌馃嵕

鑼冨洿鎻愬崌锛屸€滈瓟娉曟敞閲娾€濓紝浠ュ強鏇村鏂扮壒鎬э紒


鍦ㄥ彂甯冧簡 webpack v2 涔嬪悗锛屾垜浠浘鍚戠ぞ鍖哄仛浜嗕竴浜涙壙璇恒€傛垜浠壙璇哄皢浼氬彂甯冪敱鐢ㄦ埛绁ㄩ€夊嚭鏉ョ殑鍔熻兘銆傛澶栵紝鎴戜滑鎵胯鍙戝竷鍛ㄦ湡浼?span class="mq-8">鏇村揩锛屾洿绋冲畾銆?/p>

杩欐娌℃湁 beta 鐗堟湰锛屽畬鍏ㄥ悜涓嬪吋瀹广€傛垜浠壙璇鸿浣犱滑鈥斺€斾績杩?webpack 鎴愰暱鐨勭ぞ鍖烘垚鍛樹滑鈥斺€旀洿杞绘澗鍦颁娇鐢ㄣ€?/p>

webpack 鍥㈤槦鑷豹鍦板甯冿紝浠婂ぉ鎴戜滑鍙戝竷浜?webpack 3.0.0锛?鐜板湪灏卞彲浠ヤ笅杞芥垨鍗囩骇锛?/p>

npm install webpack@3.0.0 --save-dev

鎴栬€?/p>

yarn add webpack@3.0.0 --dev


浠?webpack 2 杩佺Щ鍒?3锛?span class="mq-18">浣犲彧闇€瑕佹墽琛屽崌绾у懡浠?/strong>锛岃€屼笉闇€瑕佷慨鏀逛换浣曚唬鐮併€傛垜浠皢杩欐鍗囩骇鏍囪涓虹増鏈殑閲嶅ぇ鍗囩骇锛屾槸鍥犱负鍐呴儴鐨勭獊鐮存€у彉鍖栧彲鑳戒細褰卞搷鏌愪簺鎻掍欢鐨勪娇鐢ㄣ€?/p>

鍒扮洰鍓嶄负姝紝98% 鐨勫崌绾х殑鐢ㄦ埛閮芥病鏈夐亣鍒颁换浣曚笉鍏煎锛?/strong>

鏈夊摢浜涙柊鐗规€?

涓婃枃宸茬粡鎻愬埌锛屾垜浠彂甯冧簡涓€浜涚敱鐢ㄦ埛鎶曠エ閫夊嚭鐨勫姛鑳斤紝鎰熻阿 Github , 璧炲姪鍟嗗拰鎴戜滑鐨勬敮鎸佽€咃紝鏈変簡浠栦滑鎴戜滑鎵嶈兘鍋氬嚭姣忎竴涓敼杩涖€傪煒?/p>

馃敩鑼冨洿鎻愬崌锛圫cope Hoisting 锛夝煍?/h3>

鑼冨洿鎻愬崌鏄?webpack 3 鐨勯噸鐐瑰姛鑳姐€備箣鍓?webpack 鍦ㄦ墦鍖呮椂锛屾偍鐨?bundle 涓殑姣忎釜妯″潡閮藉皢琚寘瑁呭湪鍗曠嫭鐨勫嚱鏁伴棴鍖呬腑銆傝繖浜涢棴鍖呬細浣挎偍鐨?JavaScript 鍦ㄦ祻瑙堝櫒涓墽琛岄€熷害鏇存參銆傜浉姣斾箣涓嬶紝鍍?Closure Compiler 鍜?RollupJS 杩欐牱鐨勫伐鍏峰彲浠ュ皢鎵€鏈夋ā鍧楀寘瑁呭湪涓€涓ぇ鐨勯棴鍖呭唴锛屼粠鑰屼娇鎮ㄧ殑浠g爜鍦ㄦ祻瑙堝櫒涓叿鏈夋洿蹇殑鎵ц閫熷害銆?/p>

webpack 3 姝e紡鍙戝竷锛岃浣犳洿鈥滃揩鈥?></p> 
<p class=濡備粖锛屼娇鐢?webpack 3锛屾偍鐜板湪灏卞彲浠?span class="mq-29">鍦ㄩ厤缃腑娣诲姞涓嬮潰鐨勬彃浠朵互鍚敤鑼冨洿鎻愬崌锛?/p>

module.exports = {

  plugins: [

    new webpack.optimize.ModuleConcatenationPlugin()

  ]

};

鑼冨洿鎻愬崌鏄熀浜?ECMAScript 妯″潡锛圡odule锛夎娉曞疄鐜扮殑涓€涓壒寰併€傞€氳繃鑼冨洿鎻愬崌锛寃ebpack 鍙互鏍规嵁浣犳鍦ㄤ娇鐢ㄧ殑妯″潡鍜?span class="mq-52">涓€浜涘叾浠栨潯浠?/span>鏉ュ垽鏂槸鍚﹂渶瑕佸洖閫€鍒版櫘閫氱殑鎵撳寘鏂瑰紡銆?/p>

涓轰簡浜嗚В浠€涔堣Е鍙戜簡杩欎簺鍥為€€锛屾垜浠坊鍔犱簡涓€涓?span class="mq-54">--display-optimization-bailout cli鏍囧織锛屽畠灏嗗憡璇変綘鏄粈涔堝鑷寸殑鍥為€€銆?/p>

webpack 3 姝e紡鍙戝竷锛岃浣犳洿鈥滃揩鈥?></p> 
<p class=鍚屾椂锛岀敱浜庤寖鍥存彁鍗囦細绉婚櫎妯″潡澶栫殑鍑芥暟鍖呰锛屼綘鍙兘浼氱湅鍒颁竴浜涘皬鐨勪綋绉敼杩涖€傜劧鑰岋紝鏇存樉钁楃殑鏀硅繘鏄?JavaScript 鍦ㄦ祻瑙堝櫒涓姞杞界殑閫熷害銆傚鏋滄偍鍦ㄦ瘮杈冧娇鐢ㄤ箣鍓嶅拰涔嬪悗鏃跺彂鐜板姞杞介€熷害鍙栧緱浜嗛潪甯告鐨勬敼杩涳紝璇烽殢鏃跺弽棣堜竴浜涙暟鎹紝鎴戜滑灏嗗緢鑽e垢鍒嗕韩锛?/p>

馃敭鈥滈瓟娉曟敞閲娾€?Magic Comments)馃敭 

褰撴垜浠湪 webpack 2 涓紩鍏ュ姩鎬佸鍏ヨ娉曪紙import()锛夌殑鐢ㄦ硶鏃讹紝鐢ㄦ埛琛ㄧず锛屼粬浠笉鑳藉儚浣跨敤require.ensure涓€鏍峰垱寤哄懡鍚嶄唬鐮佸潡锛坈hunk锛夈€?/p>

鎴戜滑鐜板湪浠嬬粛鐢辩ぞ鍖哄垱寤虹殑鈥滈瓟娉曟敞閲娾€濓紝瀹冨彲浠ヤ紶閫掍唬鐮佸潡鐨勫悕绉帮紝杩樻湁鏇村鍔熻兘锛屼緥濡傚彲浠ユ坊鍔犳洿澶氱殑鍐呰仈娉ㄩ噴鍒?span class="mq-64">import()璇彞涓€?/p>

import(/* webpackChunkName: "my-chunk-name" */ 'module');

閫氳繃浣跨敤娉ㄩ噴锛屾垜浠兘澶熷湪浣跨敤鍔ㄦ€佸鍏ヨ娉曠殑鍚屾椂锛屽浠g爜鍧楄繘琛屽懡鍚嶃€?/p>

灏界杩欐槸鎴戜滑鍦?v2.4 鍜?v2.6 涓彂甯冪殑鎶€鏈壒鎬э紝浣嗗湪 v3 涓紝鎴戜滑淇浜嗚繖浜涘姛鑳界殑涓€浜涢敊璇紝浣垮叾鍙樺緱鏇寸ǔ瀹氥€?鐜板湪鍏佽鍔ㄦ€佸鍏ヨ娉曞叿鏈変笌require.ensure鐩稿悓鐨勭伒娲绘€с€?/p>

瑕佷簡瑙f洿澶氫俊鎭紝璇峰弬闃呮垜浠?span class="mq-79">鏈€鏂版枃妗g殑浠g爜鍒嗗壊閮ㄥ垎锛屾柊鍔熻兘閮ㄥ垎宸茬粡楂樹寒锛?/p>

馃槏 鎺ヤ笅鏉ュ仛浠€涔堬紵 馃槏

鎴戜滑鏈夊緢澶氬姛鑳藉拰澧炲己鍔熻兘鎯宠鎺ㄥ嚭锛佷絾鎴戜滑闇€瑕佷簡瑙g敤鎴烽渶姹傜殑浼樺厛绾с€傛墍浠?span class="mq-82">璁块棶鎴戜滑鐨勬姇绁ㄩ〉闈紝骞舵彁鍑轰綘鎯崇湅鍒扮殑鍔熻兘锛?/span>

杩欎簺鏄垜浠笇鏈涜兘甯︾粰鎮ㄧ殑涓€浜涘姛鑳斤細

  • 鏇村ソ鍦版瀯寤虹紦瀛?/p>

  • 鏇村揩鐨勫垵濮嬫瀯寤哄拰澧為噺鏋勫缓

  • 鏇村ソ鐨?TypeScript 浣撻獙

  • 鏀硅繘闀挎湡缂撳瓨

  • WASM 妯″潡鏀寔

  • 鏀瑰杽鐢ㄦ埛浣撻獙


濂囪垶鍛ㄥ垔

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

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


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

鈻?/strong>


以上是关于webpack 3 姝e紡鍙戝竷锛岃浣犳洿鈥滃揩鈥?/h1>

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

Git 宸ヤ綔娴佺▼锛汫raphQL 浠庡叆闂ㄥ埌瀹炶返锛汚ngular 9.0 鍙戝竷锛両vy 姝e紡鎶佃揪

銆愮1203鏈熴€憌ebpack 4 鍙戝竷浜嗭紒

pig 2.8.0 鍙戝竷锛岀Щ闄?Hystrix 鎷ユ姳 Sentinel

鎶€鏈彂甯?| Forge Viewer涓嶧orge API Node.js瀹㈡埛绔疭DK鐨凾ypeScript澹版槑鏂囦欢鍙戝竷锛?/h1>