Skip to content

Commit 3f827b8

Browse files
authored
Fix for issue where firestore could not be loaded alongside firebase.js (#196)
* Add gulpfile to properly build firebase.js binary * [AUTOMATED]: Prettier Code Styling * [AUTOMATED]: License Headers * Update yarn.lock * Refactor to use external maps (THANKS @mikelehen) * Add firebase files to .prettierignore
1 parent d49daa0 commit 3f827b8

File tree

5 files changed

+210
-64
lines changed

5 files changed

+210
-64
lines changed

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# This file is pre-built and need not be formatted
22
packages/auth/src/auth.js
3+
packages/firebase/firebase*
34
dist

packages/firebase/gulpfile.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* Copyright 2017 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const concat = require('gulp-concat');
18+
const gulp = require('gulp');
19+
const sourcemaps = require('gulp-sourcemaps');
20+
const { resolve } = require('path');
21+
const webpack = require('webpack');
22+
const webpackStream = require('webpack-stream');
23+
const merge = require('merge2');
24+
25+
function compileWebpack(watch = false) {
26+
return () =>
27+
gulp
28+
.src([
29+
'./app/index.js',
30+
'./auth/index.js',
31+
'./database/index.js',
32+
'./firestore/index.js',
33+
'./messaging/index.js',
34+
'./storage/index.js'
35+
])
36+
.pipe(
37+
webpackStream(
38+
{
39+
watch,
40+
config: require('./webpack.config')
41+
},
42+
webpack
43+
)
44+
)
45+
.pipe(gulp.dest('.'));
46+
}
47+
48+
function concatFiles() {
49+
return gulp
50+
.src([
51+
'./firebase-app.js',
52+
'./firebase-auth.js',
53+
'./firebase-database.js',
54+
'./firebase-messaging.js',
55+
'./firebase-storage.js'
56+
])
57+
.pipe(sourcemaps.init({ loadMaps: true }))
58+
.pipe(concat('firebase.js'))
59+
.pipe(sourcemaps.write('.'))
60+
.pipe(gulp.dest('.'));
61+
}
62+
63+
gulp.task('compile-webpack', compileWebpack());
64+
gulp.task('concat-files', concatFiles);
65+
66+
const buildSdk = gulp.series(compileWebpack(), concatFiles);
67+
68+
gulp.task('build', buildSdk);
69+
gulp.task('watch', () => {
70+
compileWebpack(true)();
71+
gulp.watch(
72+
[
73+
'./firebase-app.js',
74+
'./firebase-auth.js',
75+
'./firebase-database.js',
76+
'./firebase-messaging.js',
77+
'./firebase-storage.js'
78+
],
79+
concatFiles
80+
);
81+
});

packages/firebase/package.json

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
},
2020
"scripts": {
2121
"dev": "run-p watch:compiler watch:server",
22-
"watch:compiler": "webpack -w --colors",
22+
"watch:compiler": "gulp watch",
2323
"watch:server": "webpack-dev-server --config webpack.dev.js --colors",
24-
"prepare": "webpack --config webpack.config.js"
24+
"prepare": "gulp build"
2525
},
2626
"main": "index.node.js",
2727
"browser": "index.js",
@@ -30,18 +30,22 @@
3030
"@firebase/auth": "0.1.0",
3131
"@firebase/database": "0.1.0",
3232
"@firebase/firestore": "0.1.0",
33-
"@firebase/polyfill": "0.1.0",
3433
"@firebase/messaging": "0.1.0",
34+
"@firebase/polyfill": "0.1.0",
3535
"@firebase/storage": "0.1.0",
3636
"dom-storage": "^2.0.2",
3737
"xmlhttprequest": "^1.8.0"
3838
},
3939
"devDependencies": {
4040
"compression-webpack-plugin": "^1.0.0",
4141
"git-rev-sync": "^1.9.1",
42+
"gulp": "gulpjs/gulp#4.0",
43+
"gulp-concat": "^2.6.1",
44+
"gulp-sourcemaps": "^2.6.1",
4245
"npm-run-all": "^4.1.1",
4346
"webpack": "^3.5.6",
4447
"webpack-dev-server": "^2.8.1",
48+
"webpack-stream": "^4.0.0",
4549
"wrapper-webpack-plugin": "^1.0.0"
4650
},
4751
"typings": "index.d.ts"

packages/firebase/webpack.config.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,6 @@ const baseConfig = {
5959
}
6060
};
6161

62-
const singleExport = Object.assign({}, baseConfig, {
63-
entry: {
64-
firebase: resolve(__dirname, 'index.js')
65-
},
66-
output: Object.assign({}, baseConfig.output, {
67-
library: 'firebase',
68-
libraryTarget: 'window'
69-
})
70-
});
71-
7262
function isFirebaseApp(fileName) {
7363
const pathObj = parse(fileName);
7464
return pathObj.name === 'firebase-app';
@@ -114,4 +104,4 @@ const multiExport = Object.assign({}, baseConfig, {
114104
]
115105
});
116106

117-
module.exports = [singleExport, multiExport];
107+
module.exports = [multiExport];

0 commit comments

Comments
 (0)