Firebase firestore server timestamp without importing all of firebase to my web project?

一个人想着一个人 提交于 2021-02-11 15:14:02

问题


I am using Firebase in a React web app and I need to use firebase.firestore.FieldValue.serverTimestamp() and some other methods.

However to get a firebase reference I import import * as firebase from "firebase";

Doing this import gives me the following console warning:

It looks like you're using the development build of the Firebase JS SDK.
When deploying Firebase apps to production, it is advisable to only import
the individual SDK components you intend to use.

For the module builds, these are available in the following manner
(replace <PACKAGE> with the name of a component - i.e. auth, database, etc):

CommonJS Modules:
const firebase = require('firebase/app');
require('firebase/<PACKAGE>');

ES Modules:
import firebase from 'firebase/app';
import 'firebase/<PACKAGE>';

Typescript:
import * as firebase from 'firebase/app';
import 'firebase/<PACKAGE>';

How can I import firebase.firestore.FieldValue.serverTimestamp() without importing the whole firebase library?


回答1:


Installing the following package:

https://www.npmjs.com/package/@firebase/firestore

Then you can do:

import firebase from '@firebase/app';
import '@firebase/firestore' 


来源:https://stackoverflow.com/questions/61109729/firebase-firestore-server-timestamp-without-importing-all-of-firebase-to-my-web

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!