Skip to content

Commit

Permalink
Fix for issue where firestore could not be loaded alongside firebase.…
Browse files Browse the repository at this point in the history
…js (firebase#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
  • Loading branch information
jshcrowthe authored Oct 9, 2017
1 parent d49daa0 commit 3f827b8
Show file tree
Hide file tree
Showing 5 changed files with 210 additions and 64 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# This file is pre-built and need not be formatted
packages/auth/src/auth.js
packages/firebase/firebase*
dist
81 changes: 81 additions & 0 deletions packages/firebase/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
* Copyright 2017 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

const concat = require('gulp-concat');
const gulp = require('gulp');
const sourcemaps = require('gulp-sourcemaps');
const { resolve } = require('path');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const merge = require('merge2');

function compileWebpack(watch = false) {
return () =>
gulp
.src([
'./app/index.js',
'./auth/index.js',
'./database/index.js',
'./firestore/index.js',
'./messaging/index.js',
'./storage/index.js'
])
.pipe(
webpackStream(
{
watch,
config: require('./webpack.config')
},
webpack
)
)
.pipe(gulp.dest('.'));
}

function concatFiles() {
return gulp
.src([
'./firebase-app.js',
'./firebase-auth.js',
'./firebase-database.js',
'./firebase-messaging.js',
'./firebase-storage.js'
])
.pipe(sourcemaps.init({ loadMaps: true }))
.pipe(concat('firebase.js'))
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('.'));
}

gulp.task('compile-webpack', compileWebpack());
gulp.task('concat-files', concatFiles);

const buildSdk = gulp.series(compileWebpack(), concatFiles);

gulp.task('build', buildSdk);
gulp.task('watch', () => {
compileWebpack(true)();
gulp.watch(
[
'./firebase-app.js',
'./firebase-auth.js',
'./firebase-database.js',
'./firebase-messaging.js',
'./firebase-storage.js'
],
concatFiles
);
});
10 changes: 7 additions & 3 deletions packages/firebase/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
},
"scripts": {
"dev": "run-p watch:compiler watch:server",
"watch:compiler": "webpack -w --colors",
"watch:compiler": "gulp watch",
"watch:server": "webpack-dev-server --config webpack.dev.js --colors",
"prepare": "webpack --config webpack.config.js"
"prepare": "gulp build"
},
"main": "index.node.js",
"browser": "index.js",
Expand All @@ -30,18 +30,22 @@
"@firebase/auth": "0.1.0",
"@firebase/database": "0.1.0",
"@firebase/firestore": "0.1.0",
"@firebase/polyfill": "0.1.0",
"@firebase/messaging": "0.1.0",
"@firebase/polyfill": "0.1.0",
"@firebase/storage": "0.1.0",
"dom-storage": "^2.0.2",
"xmlhttprequest": "^1.8.0"
},
"devDependencies": {
"compression-webpack-plugin": "^1.0.0",
"git-rev-sync": "^1.9.1",
"gulp": "gulpjs/gulp#4.0",
"gulp-concat": "^2.6.1",
"gulp-sourcemaps": "^2.6.1",
"npm-run-all": "^4.1.1",
"webpack": "^3.5.6",
"webpack-dev-server": "^2.8.1",
"webpack-stream": "^4.0.0",
"wrapper-webpack-plugin": "^1.0.0"
},
"typings": "index.d.ts"
Expand Down
12 changes: 1 addition & 11 deletions packages/firebase/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,6 @@ const baseConfig = {
}
};

const singleExport = Object.assign({}, baseConfig, {
entry: {
firebase: resolve(__dirname, 'index.js')
},
output: Object.assign({}, baseConfig.output, {
library: 'firebase',
libraryTarget: 'window'
})
});

function isFirebaseApp(fileName) {
const pathObj = parse(fileName);
return pathObj.name === 'firebase-app';
Expand Down Expand Up @@ -114,4 +104,4 @@ const multiExport = Object.assign({}, baseConfig, {
]
});

module.exports = [singleExport, multiExport];
module.exports = [multiExport];
Loading

0 comments on commit 3f827b8

Please sign in to comment.