1 回答
TA貢獻1712條經驗 獲得超3個贊
正如該鏈接所說:
您應該導入單個組件,例如:react-bootstrap/Button而不是整個庫。這樣做只會引入您使用的特定組件,這可以顯著減少您最終發送給客戶端的代碼量。
如果您從 導入,客戶react-bootstrap端將不得不下載. 這最終可能會成為相當大的代碼塊。相反,如果您從 中導入,則只需下載按鈕即可 - 不包含任何無關內容。react-bootstrapreact-bootstrap/Button
比較文件:
https://github.com/react-bootstrap/react-bootstrap/blob/master/src/Button.js
到
https://github.com/react-bootstrap/react-bootstrap/blob/master/src/index.js
如您所見,從 Button 導入需要一些導入:
import classNames from 'classnames';
import React from 'react';
import PropTypes from 'prop-types';
import { useBootstrapPrefix } from './ThemeProvider';
import SafeAnchor from './SafeAnchor';
但是從 中導入index.js需要非常大量的導入,準確地說是77 。
export Accordion from './Accordion';
export AccordionToggle, { useAccordionToggle } from './AccordionToggle';
export AccordionCollapse from './AccordionCollapse';
export Alert from './Alert';
export Badge from './Badge';
// and 72 more
如果您 import fromindex而不是 from Button,那么您將下載大量不需要的代碼,沒有充分的理由。
添加回答
舉報
