Ôõôµ÷ÊÔReactÔ´Â룿¶àÖÖ¹¤¾ßϵĵ÷ÊÔÒªÁìÏÈÈÝ
Ôõôµ÷ÊÔreactÔ´Â룿ÏÂÃ汾ƪÎÄÕ´ø¸÷ÈËÁÄÁĶàÖÖ¹¤¾ßϵĵ÷ÊÔreactÔ´ÂëµÄÒªÁ죬ÏÈÈÝÒ»ÏÂÔÚТ˳Õß¡¢create-react-app¡¢viteÏîÄ¿ÖÐÔõÑùdebugger reactµÄÕæʵԴÂ룬ϣÍû¶Ô¸÷ÈËÓÐËù×ÊÖú£¡
clone React
½«Reactcloneµ½ÍâµØ£¬²¢×°ÖÃÒÀÀµ.
git clone https://github.com/facebook/react.git
µÇ¼ºó¸´ÖÆ
±àÒëÏîÄ¿
ÈôÊÇÖ»ÊÇͨ¹ý¼òÆÓµÄyarn build£¬²¢²»»áÌìÉúsourcemap, Õâ²»ÊÇÎÒÃÇÏëÒªµÄ£¬ÎÒÃÇÐèÒª±àÒë·ºÆð´ú±à¼Æ÷ËùÐèµÄsourcemap¾ÙÐÐÓ³Éäµ½ÏÖʵԴÂë¾ÙÐе÷ÊÔ¡£
Ä¿½ñreactÏîÄ¿²¢ÎÞ·¨Í¨¹ý¼òÆÓÔöÌí²ÎÊýÌìÉúsourcemap£¬ÎÒÃÇÐèÒªÐÞ¸Äscripts/rollup/build.jsϵIJ¿·ÖÉèÖà ¡¾ÍƼöѧϰ£ºvscode½Ì³Ì¡¢±à³Ì½Ìѧ¡¿
¢Ù: ÐÞ¸Ä sourcemap Ϊ true¢Ú£º×¢ÊͲ¿·ÖÎÞ·¨ÌìÉúsourcemapµÄ²å¼þ
ok£¬¿´ÆðÀ´Ðí¶à£¬µ«×Åʵ´óÖ¶¼Á¬ÔÚÒ»Æð(353-355, 387-415), ×¢Ê͵ôÁ˼¸¸ö²å¼þ£¬´ËʱÎÒÃÇ¿ÉÒÔ¾ÙÐÐbuildÁË
yarn build
µÇ¼ºó¸´ÖÆ
×¢ÖØ: ÈôÊÇbuildʧ°Ü£¬ÌáÐÑÄãÐèҪװÖÃjdk£¬Æ¾Ö¤±¨´í×°Öü´¿É¡£
ÀÖЧ¹û¹ûÈçÏ£º
¾ÙÐÐdebugger
ÎÒÃÇƾ֤¹Ù·½ÎĵµµÃÖª»ù´¡¿ª·¢ÎļþĿ¼ÔÚ /fixtures/packaging/babel-standalone/dev.htmlÖУ¬ÓÚÊÇÎÒÃÇƾ֤¸ÃhtmlÏȾÙÐмòÆÓµÄdebugÉèÖá£
vscode
1¡¢½¨ÉèÒ»¸ölaunch.json
2¡¢ÐÞ¸Älaunch.jsonÉèÖÃ
{ // ʹÓà IntelliSense Ïà֪Ȥ¹ØÊôÐÔ¡£ // ÐüÍ£ÒÔÉó²éÏÖÓÐÊôÐÔµÄÐÎò¡£ // ÓûÏàʶ¸ü¶àÐÅÏ¢£¬Çë»á¼û: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "type": "chrome", "request": "launch", "name": "Open dev.html", // ÕâÀï·¾¶¿ÉÄÜ·×ÆçÑù ×öͳһµ÷½â ÐÞ¸ÄΪÈçÏ "file": "${workspaceFolder}/fixtures/packaging/babel-standalone/dev.html" } ] }
µÇ¼ºó¸´ÖÆ
È»ºóÔÚÔ´Âë´òÉ϶ϵ㣬µã»÷·¿ªdebug¼´¿É¿´µ½ÔËÐе½Ô´ÂëÀÖ³É.
×¢ÖØ£º´ËʱÎÒÃÇÒѾÓÐÁËsourcemap£¬Ö±½ÓÔÚ/packages/react-dom»òÕß/packages/react»áÔËÐе½´úÂë´òÉ϶ϵã
webstrom
webstromµÄÊ®·Ö¼òÆÓ£¬ÔÚdev.htmlÓÒ¼ü¾ÙÐе÷ÊÔdev.html¼´¿É:
ÈçÉÏÃæµÄ°¸ÀýÒѾ֪×ãÄãµÄ´ó²¿·ÖµÄÔ´Âëµ÷ÊÔÐèÇ󣬲¢ÇÒÎÒÃÇÒ²¿ÉÒÔͨ¹ýÔöÌíһЩ×é¼þ»òÕßhookÀ´¾ÙÐе÷ÊÔ:
ÈôÊÇÄã×ÅʵÏëÔÚÕæʵÏîÄ¿ÖоÙÐÐÔ´ÂëÔĶÁ£¬¿ÉÒÔ¼ÌÐøÍùÏÂÔĶÁ¡£
ÔÚcreate-react-appÖÐdebug
ÎÒÃÇƽʱ´ó¶à¶¼»ùÓÚcreate-react-app»òÕßviteÀ´ÔËÐÐÏîÄ¿£¬ÎÒÃÇ¿ÉÒÔͨ¹ýnpm linkÀ´¾ÙÐжÔÔ´ÂëµÄÁ´½Ó¡£
ÉÏÃæµÄ°¸ÀýÊʺÏreact¿ª·¢ÕßʹÓò¢ÇÒÒѾ֪×ãÄãµÄС²¿·ÖÐèÇ󣬿ÉÊÇÎÒÃÇƽʱ´ó¶à¶¼»ùÓÚcreate-react-app»òÕßviteÀ´ÔËÐÐÏîÄ¿£¬ÎÒÃÇ¿ÉÒÔͨ¹ýnpm linkÀ´Á´½Óһϼ´¿É¡£
¢Ù: ½¨ÉèÒ»¸öcreate-react-appÏîÄ¿
¢Ú: ÔÚReactÏîÄ¿Öн« react,react-domÁ´½Óµ½È«¾Ö.
×¢ÖØ: ÐèҪƾ֤ÄãÏÖʵĿ½ñ´¦ÓÚµÄλÖÃÈ¥Ö´ÐУ¬×ܶøÑÔÖ®¾ÍÊǵ½build/node_modules/reactºÍbuild/node_modules/react-dom»®·ÖÖ´ÐÐnpm link¾ÍÐÐÀ².
cd build/node_modules/react && npm link
µÇ¼ºó¸´ÖÆ
ÈçϾÍÀÖ³ÉÁËÒ»¸ö:
ÔÙ°Ñreact-domÒ²link°É.
cd .. && cd react-dom && npm link
µÇ¼ºó¸´ÖÆ
¢Û: ÔÚcreate-react-appµÄÏîÄ¿ÖÐlink reactÓëreact-dom
npm link react react-dom
µÇ¼ºó¸´ÖÆ
´ó¹¦Ð¡³É£¬½ÓÏÂÀ´×îÏÈÕýʽµÄdebugger.
vscodeÔõÑùdebugger
¹Ù·½ÒѾ¸ø³ö²¿·ÖÎĵµ, ²Î¿¼Îĵµ: Îĵµ
ÏÈÆô¶¯ÏîÄ¿ yarn start
ÔöÌílaunch.jsonÉèÖÃ: Îĵµ
×¢ÖØ:
1¡¢ÈôÊÇÄãÏîÄ¿¶Ë¿Ú¾ÙÐÐÁËÐ޸ģ¬ÐèÒª°ÑÉÏ·½µÄ¶Ë¿ÚÒ²×öÐÞ¸Ä.
2¡¢¹Ù·½ÌṩµÄÊÇedgeä¯ÀÀÆ÷£¬ÈôÊÇÄãÏë¸Ä¹È¸èä¯ÀÀÆ÷Ö»ÐèÒª°ÑtypeÐÞ¸ÄΪchrome
±ÊÕßµÄÉèÖÃÈçÏÂ:
{ "version": "0.2.0", "configurations": [ { "type": "chrome", "request": "launch", "name": "µ÷ÊÔcreat-react-appÔ´Âë", "url": "http://localhost:3000", "webRoot": "${workspaceFolder}" } ] }
µÇ¼ºó¸´ÖÆ
ÕÒ¸öλÖôòÉ϶ϵã¾ÙÐе÷ÊÔ¢Û¡¢¢ÜΪÎÒ´òÉ϶ϵãµÄλÖ㬵ã»÷ ¢Ý ¼´¿É¿´µ½½øÈëÔ´ÂëÀ²(¿ÉÄÜÒª¶àµã¼¸ÏÂ)
ÖÁ´Ë£ºÎÒÃÇÒѾ´ó¹¦¸æ³É£¬¿ÉÒÔ¾ÙÐÐÔ´Âëµ÷ÊÔ¡£
webstromÔõÑùdebugger
webstorm¾ÍÏÔµÃÊ®·Ö¼òÆÓ£¬²Î¿¼¹Ù·½Îĵµ: Îĵµ
´òÉ϶ϵã
Æô¶¯ÏîÄ¿ yarn start
ʹÓð´¼ü·¿ªµ÷ÊÔÃæ°å, Îĵµ
µ÷ÊÔReact viteÏîÄ¿
ºÍÉÏ·½Ò»Ö£¬Ò²ÊÇͨ¹ýlink
×ܽ᣺
µ÷ÊÔÔ´ÂëµÄÂß¼½¹µãÔÚÓÚsourcemap£¬¿ÉÊÇÎÒÃDz»ÄÑ·¢Ã÷ÆäÖб£´æһЩÎÊÌâ:
1¡¢Ä¿½ñÎÒÃÇ¿çÏîÄ¿¾ÙÐе÷ÊÔ£¨Ô´ÂëÔÚreactÏîÄ¿ÖУ¬×ðÁú¿Ê±ÏîÄ¿ÔÚÁíÍâÒ»¸öÎļþÖУ©£¬µ¼ÖÂÀàÐÍÖÎÀí·ºÆðÎÊÌâ, ÕâÊÇ»ùÓÚ¿ª·¢ÏîÄ¿µÄ½ç˵ÖÎÀí£¬²î±ð±à¼Æ÷ÌåÏÖ²î±ð.
vscodeÕâÊÇÓÉÓÚvscodeĬÈÏÆÊÎötsµÄ£¬¿ÉÊDz»»áĬÊìϤ±ðflowµÄÓï·¨£¬ÒÔÊÇÕâÖֵĴúÂë»áÆÊÎö³ÉtsÓï·¨£¬¾Í»á±¨´í£¬ÎÒÃÇÔÚÏîÄ¿ÔöÌí .vscode/settings.json ÔöÌíÉèÖÃ:
{ "javascript.validate.enable": false }
µÇ¼ºó¸´ÖÆ
¼´ÌåÏÖÕý³££¬²»ÔÙ±¨´í:
webstorm
webstromÔòÊÇÎÞ·¨ÕÒµ½½ç˵
¸ü¶à¹ØÓÚVSCodeµÄÏà¹Ø֪ʶ£¬Çë»á¼û£ºvscode»ù´¡½Ì³Ì£¡
ÒÔÉϾÍÊÇÔõôµ÷ÊÔReactÔ´Â룿¶àÖÖ¹¤¾ßϵĵ÷ÊÔÒªÁìÏÈÈݵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡