Skip to content

Commit 2615fcf

Browse files
committed
Update README
1 parent a075b5f commit 2615fcf

File tree

1 file changed

+53
-93
lines changed

1 file changed

+53
-93
lines changed

packages/firebase/README.md

Lines changed: 53 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Build Status](https://travis-ci.org/firebase/firebase-js-sdk.svg?branch=master)](https://travis-ci.org/firebase/firebase-js-sdk)
1+
<!-- [![Build Status](https://travis-ci.org/firebase/firebase-js-sdk.svg?branch=master)](https://travis-ci.org/firebase/firebase-js-sdk) -->
22

33
# Firebase - App success made simple
44

@@ -36,16 +36,31 @@ you should use the
3636

3737
## Get the code (browser)
3838

39-
### Script include
40-
>This brings in all Firebase features. See
41-
>["Include only the features you need"](#include-only-the-features-you-need)
42-
>below for
43-
>how to minimize download size by only including the scripts you need.
39+
We recommend only installing the features you need. The individually installable services are:
4440

45-
Include Firebase in your web application via a `<script>` tag:
41+
- `firebase-app` - The core `firebase` client (required).
42+
- `firebase-analytics` - Firebase Analytics (optional).
43+
- `firebase-auth` - Firebase Authentication (optional).
44+
- `firebase-database` - The Firebase Realtime Database (optional).
45+
- `firebase-firestore` - Cloud Firestore (optional).
46+
- `firebase-storage` - Firebase Storage (optional).
47+
- `firebase-messaging` - Firebase Cloud Messaging (optional).
48+
- `firebase-functions` - Firebase Cloud Functions (optional).
49+
- `firebase-remote-config` - Firebase Remote Config (optional).
50+
- `firebase-performance` - Firebase Performance (optional).
51+
52+
### Script include
53+
Include Firebase in your web application via `<script>` tags. Create a script tag for each of the individual services you use (include `firebase-app`
54+
first):
4655

4756
```html
48-
<script src="https://www.gstatic.com/firebasejs/${JSCORE_VERSION}/firebase.js"></script>
57+
<script src="https://www.gstatic.com/firebasejs/${FIREBASE_VERSION}/firebase-app.js"></script>
58+
<script src="https://www.gstatic.com/firebasejs/${FIREBASE_VERSION}/firebase-auth.js"></script>
59+
<script src="https://www.gstatic.com/firebasejs/${FIREBASE_VERSION}/firebase-database.js"></script>
60+
<script src="https://www.gstatic.com/firebasejs/${FIREBASE_VERSION}/firebase-firestore.js"></script>
61+
<script src="https://www.gstatic.com/firebasejs/${FIREBASE_VERSION}/firebase-storage.js"></script>
62+
<script src="https://www.gstatic.com/firebasejs/${FIREBASE_VERSION}/firebase-messaging.js"></script>
63+
<script src="https://www.gstatic.com/firebasejs/${FIREBASE_VERSION}/firebase-functions.js"></script>
4964

5065
<script>
5166
var app = firebase.initializeApp({
@@ -54,7 +69,8 @@ Include Firebase in your web application via a `<script>` tag:
5469
databaseURL: '<your-database-url>',
5570
projectId: '<your-cloud-firestore-project>',
5671
storageBucket: '<your-storage-bucket>',
57-
messagingSenderId: '<your-sender-id>'
72+
messagingSenderId: '<your-sender-id>',
73+
appId: '<your-app-id>'
5874
});
5975
// ...
6076
</script>
@@ -64,86 +80,31 @@ _Note: To get a filled in version of the above code snippet, go to the
6480
[Firebase console](https://console.firebase.google.com/) for your app and click on "Add
6581
Firebase to your web app"._
6682

67-
### npm bundler (Browserify, Webpack, etc.)
68-
69-
>This brings in all Firebase features. See
70-
>["Include only the features you need"](#include-only-the-features-you-need)
71-
>below for
72-
>how to minimize bundle size by only importing the features you need.
73-
74-
The Firebase JavaScript npm package contains code that can be run in the browser
75-
after combining the modules you use with a package bundler (e.g.,
76-
[Browserify](http://browserify.org/), [Webpack](https://webpack.github.io/)).
83+
#### Alternative - all-in-one import
7784

78-
Install the Firebase npm module:
85+
>This brings in all Firebase features. We recommend the method above to
86+
>minimize download size by only including the scripts you need.
7987
80-
```
81-
$ npm init
82-
$ npm install --save firebase
83-
```
84-
85-
In your code, you can access Firebase using:
86-
87-
```js
88-
var firebase = require('firebase');
89-
var app = firebase.initializeApp({ ... });
90-
```
91-
92-
If you are using ES6 imports or TypeScript:
93-
94-
```js
95-
import firebase from 'firebase';
96-
var app = firebase.initializeApp({ ... });
97-
```
98-
99-
### Include only the features you need
100-
101-
The full Firebase JavaScript client includes support for Firebase Authentication, the
102-
Firebase Realtime Database, Firebase Storage, and Firebase Cloud Messaging. Including
103-
code via the above snippets will pull in all of these features.
104-
105-
You can reduce the amount of code your app uses by just including the features
106-
you need. The individually installable services are:
107-
108-
- `firebase-app` - The core `firebase` client (required).
109-
- `firebase-auth` - Firebase Authentication (optional).
110-
- `firebase-database` - The Firebase Realtime Database (optional).
111-
- `firebase-firestore` - Cloud Firestore (optional).
112-
- `firebase-storage` - Firebase Storage (optional).
113-
- `firebase-messaging` - Firebase Cloud Messaging (optional).
114-
- `firebase-functions` - Firebase Cloud Functions (optional).
115-
116-
From the CDN, include the individual services you use (include `firebase-app`
117-
first):
88+
Include Firebase in your web application via a `<script>` tag:
11889

11990
```html
120-
<script src="https://www.gstatic.com/firebasejs/${FIREBASE_VERSION}/firebase-app.js"></script>
121-
<script src="https://www.gstatic.com/firebasejs/${FIREBASE_VERSION}/firebase-auth.js"></script>
122-
<script src="https://www.gstatic.com/firebasejs/${FIREBASE_VERSION}/firebase-database.js"></script>
123-
<script src="https://www.gstatic.com/firebasejs/${FIREBASE_VERSION}/firebase-firestore.js"></script>
124-
<script src="https://www.gstatic.com/firebasejs/${FIREBASE_VERSION}/firebase-storage.js"></script>
125-
<script src="https://www.gstatic.com/firebasejs/${FIREBASE_VERSION}/firebase-messaging.js"></script>
126-
<script src="https://www.gstatic.com/firebasejs/${FIREBASE_VERSION}/firebase-functions.js"></script>
91+
<script src="https://www.gstatic.com/firebasejs/${JSCORE_VERSION}/firebase.js"></script>
12792

12893
<script>
12994
var app = firebase.initializeApp({ ... });
13095
// ...
13196
</script>
13297
```
13398

134-
When using the firebase npm package, you can `require()` just the services that
135-
you use:
99+
### NPM Bundler (Browserify, Webpack, Rollup, etc.)
136100

137-
```js
138-
var firebase = require('firebase/app');
139-
require('firebase/auth');
140-
require('firebase/database');
141-
142-
var app = firebase.initializeApp({ ... });
101+
Install the Firebase NPM module:
102+
```
103+
$ npm init
104+
$ npm install --save firebase
143105
```
144106

145-
If you are using TypeScript with the npm package, you can import just the
146-
services you use:
107+
In your code, you can import the services you use:
147108

148109
```js
149110
// This import loads the firebase namespace along with all its type information.
@@ -154,6 +115,20 @@ import 'firebase/auth';
154115
import 'firebase/database';
155116
```
156117

118+
Or if using `require()`:
119+
120+
_We recommend the `.default` import from `firebase/app` in order for
121+
typings to work correctly.
122+
See [release notes for 8.0.0](https://firebase.google.com/support/release-notes/js#version_800_-_october_26_2020)._
123+
124+
```js
125+
var firebase = require('firebase/app').default;
126+
require('firebase/auth');
127+
require('firebase/database');
128+
129+
var app = firebase.initializeApp({ ... });
130+
```
131+
157132
_The type information from the import statement will include all of the SDKs,
158133
not just the ones you have `required`, so you could get a runtime error if you
159134
reference a non-required service._
@@ -177,7 +152,9 @@ $ npm install --save firebase
177152
In your code, you can access Firebase using:
178153

179154
```js
180-
var firebase = require('firebase');
155+
var firebase = require('firebase/app').default;
156+
require('firebase/auth');
157+
require('firebase/database');
181158
var app = firebase.initializeApp({ ... });
182159
// ...
183160
```
@@ -196,23 +173,6 @@ import 'firebase/database';
196173

197174
_Known issue for typescript users with --experimental-modules: you have to set allowSyntheticDefaultImports to true in tsconfig.json to pass the type check. Use it with caution since it makes the assumption that all modules have a default export, which might not be the case for the other dependencies you have. And Your code will break if you try to import the default export from a module that doesn't have default export._
198175

199-
Firebase Storage is not included in the server side Firebase npm module.
200-
Instead, you can use the
201-
[`google-cloud` Node.js client](https://github.com/GoogleCloudPlatform/google-cloud-node).
202-
203-
```
204-
$ npm install --save google-cloud
205-
```
206-
207-
In your code, you can access your Storage bucket using:
208-
209-
```js
210-
var gcloud = require('google-cloud')({ ... });
211-
var gcs = gcloud.storage();
212-
var bucket = gcs.bucket('<your-firebase-storage-bucket>');
213-
...
214-
```
215-
216176
Firebase Cloud Messaging is not included in the server side Firebase npm module.
217177
Instead, you can use the
218178
[Firebase Cloud Messaging Rest API](https://firebase.google.com/docs/cloud-messaging/send-message).

0 commit comments

Comments
 (0)