问题
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