I found a solution: I can import the firebase module, use it during typescript compilation, and finally exclude it from my bundle through webpack externals config:
In my html code:
<script src="https://www.gstatic.com/firebasejs/8.2.6/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.6/firebase-firestore.js"></script>
<script src="bundle.js"></script>
In my typescript code:
import firebase from "firebase";
firebase.initializeApp(...
In webpack.config.js:
externals: ["firebase"],
I have verified that my bundle is much slimmer: from 139kB to 53kB.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…