2 回答
TA貢獻(xiàn)1821條經(jīng)驗(yàn) 獲得超5個(gè)贊
您在哪里讀到使用卷曲導(dǎo)入會(huì)增加捆綁包大小,這是相反的,
// below line will import everything
import * as reactstrap from 'reactstrap'
但
// this will import only specific module
import { Jumbotron } from 'reactstrap'
通過這條線:
// will import from /reactstrap/index.js
import Jumbotron from 'reactstrap';
您沒有導(dǎo)入任何內(nèi)容 https://github.com/reactstrap/reactstrap/blob/master/src/index.js,因?yàn)榇嬖趯?dǎo)出默認(rèn)值
所以我不知道它以前在你的案例中是如何工作的
下行:
// and this line is not inside the /reactstrap/index.js but /reactstrap/Jumbotron.js
export default Jumbotron;
是在這里 : https://github.com/reactstrap/reactstrap/blob/master/src/Jumbotron.js
所以你可以做:
import { Jumbotron } from 'reactstrap'
TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超5個(gè)贊
這取決于您的構(gòu)建設(shè)置和/或庫代碼的設(shè)置方式。某些庫的構(gòu)建方式在使用大括號(hào)時(shí)不會(huì)導(dǎo)入整個(gè)庫。您還可以在構(gòu)建工具中啟用一些稱為“樹抖動(dòng)”的功能,這將刪除所有未使用的代碼。
我猜你想做的是單獨(dú)導(dǎo)入Jumbotron,當(dāng)你不確定是否會(huì)導(dǎo)入整個(gè)庫時(shí),這是一個(gè)安全的賭注。同樣,這取決于庫的文件結(jié)構(gòu),但您可能在導(dǎo)入中缺少子目錄。每個(gè)組件的node_module文件夾內(nèi)都應(yīng)該有目錄??赡苁穷愃频臇|西。您看到的默認(rèn)導(dǎo)出可能位于該文件上。當(dāng)您使用時(shí),您要求它為庫的“主”文件找到默認(rèn)導(dǎo)出。這將在庫的文件中定義。node_modules/reactstrap/JumbotronJumbotronimport Jumbotron from 'reactstrap'package.json
您需要做的是將子目錄添加到導(dǎo)入中,如下所示(只是在這里猜測(cè))。只要想想作為庫的根目錄,你可以像往常一樣選擇任何文件。import Jumbotron from 'reactstrap/Jumbotron'reactstrap/
如果您使用的是webpack,那么有一個(gè)很棒的插件,您可以在其中檢查捆綁包中包含的內(nèi)容,以確保您確實(shí)只導(dǎo)入所需的代碼 https://github.com/webpack-contrib/webpack-bundle-analyzer
添加回答
舉報(bào)
