C
C
CoCoCoder2020-07-30 16:46:54
JavaScript
CoCoCoder, 2020-07-30 16:46:54

How to import only auth from firebase?

There is such a Firebase file:

import * as firebase from "firebase/app";
import "firebase/auth";
import "firebase/database";

var firebaseConfig = {
    apiKey: "smth",
    authDomain: "smth",
    databaseURL: "smth",
    projectId: "smth",
    storageBucket: "smth",
    messagingSenderId: "smth",
    appId: "smth"
};

firebase.initializeApp(firebaseConfig);

export let auth = firebase.auth();
export let database = firebase.database();

What is my idea: I want to import auth into one js file, and database.
The first js file looks like this:
import { auth } from "./firebase.js";
//какой-то код, который работает

The second is like this:
import { database } from "./firebase.js";
//какой-то код, который тоже работает

But at the same time, they have the same file size and it is equal to 400kb. That is, it seems that I am importing all the Firebase modules into each of them.
Here is the webpack config if anyone is interested:
const path = require("path");

module.exports = {
  entry: {
        auth: "./source/js/auth.js",
        listRequests: "./source/js/listRequests.js",
    },
  output: {
    filename: "[name].bundle.js",
    path: path.resolve(__dirname, "source/js")
  },
  devServer: {
     contentBase: path.join(__dirname, 'source/'),
    port: 3000
  }
}

So the question is how to import only what I need? Because even when I import only the function I need, everything else flies into the JS file, which is why the size of the JS file becomes, well, disproportionately huge.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question