Skip to content

Commit c3e07b6

Browse files
committed
refactor(*): refactor environment builds to be based on separate .ts files
1 parent 390bacd commit c3e07b6

File tree

6 files changed

+104
-111
lines changed

6 files changed

+104
-111
lines changed

gulp/config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ module.exports = {
4545
babel: {
4646
plugins: [
4747
require('babel-plugin-add-module-exports'),
48-
require('babel-plugin-minify-dead-code-elimination')
4948
],
5049
presets: [
5150
[require('babel-preset-env'), {

gulp/tasks/build.js

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -193,27 +193,6 @@ function compileIndvES2015ModulesToBrowser() {
193193
.pipe(gulp.dest(`${config.paths.outDir}/browser`));
194194
}
195195

196-
function compileSDKES2015ToBrowser() {
197-
return gulp.src('./dist/es2015/firebase.js')
198-
.pipe(webpackStream({
199-
plugins: [
200-
new webpack.DefinePlugin({
201-
TARGET_ENVIRONMENT: JSON.stringify('browser')
202-
})
203-
]
204-
}, webpack))
205-
.pipe(sourcemaps.init({ loadMaps: true }))
206-
.pipe(through.obj(function(file, enc, cb) {
207-
// Dont pipe through any source map files as it will be handled
208-
// by gulp-sourcemaps
209-
var isSourceMap = /\.map$/.test(file.path);
210-
if (!isSourceMap) this.push(file);
211-
cb();
212-
}))
213-
.pipe(sourcemaps.write('.'))
214-
.pipe(gulp.dest(`${config.paths.outDir}/browser`));
215-
}
216-
217196
function buildBrowserFirebaseJs() {
218197
return gulp.src('./dist/browser/*.js')
219198
.pipe(sourcemaps.init({ loadMaps: true }))
@@ -223,32 +202,18 @@ function buildBrowserFirebaseJs() {
223202
}
224203

225204
function buildAltEnvFirebaseJs() {
226-
const envs = [
227-
'browser',
228-
'node',
229-
'react-native'
230-
];
231-
232-
const streams = envs.map(env => {
233-
const babelConfig = Object.assign({}, config.babel, {
234-
plugins: [
235-
['inline-replace-variables', {
236-
'TARGET_ENVIRONMENT': env
237-
}],
238-
...config.babel.plugins
239-
]
240-
});
241-
return gulp.src('./dist/es2015/firebase.js')
242-
.pipe(sourcemaps.init({ loadMaps: true }))
243-
.pipe(babel(babelConfig))
244-
.pipe(rename({
245-
suffix: `-${env}`
246-
}))
247-
.pipe(sourcemaps.write('.'))
248-
.pipe(gulp.dest(`${config.paths.outDir}/cjs`));
205+
const babelConfig = Object.assign({}, config.babel, {
206+
plugins: config.babel.plugins
249207
});
250-
251-
return merge(streams);
208+
return gulp.src([
209+
'./dist/es2015/firebase-browser.js',
210+
'./dist/es2015/firebase-node.js',
211+
'./dist/es2015/firebase-react-native.js',
212+
])
213+
.pipe(sourcemaps.init({ loadMaps: true }))
214+
.pipe(babel(babelConfig))
215+
.pipe(sourcemaps.write('.'))
216+
.pipe(gulp.dest(`${config.paths.outDir}/cjs`));
252217
}
253218

254219
function copyPackageContents() {

src/firebase-browser.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
import firebase from "./app";
18+
import './auth';
19+
import './database';
20+
import './storage';
21+
import './messaging';
22+
23+
// Export the single instance of firebase
24+
export default firebase;

src/firebase-node.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
import firebase from "./app";
18+
import './auth';
19+
import './database';
20+
import './database/nodePatches';
21+
22+
23+
var Storage = require('dom-storage');
24+
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
25+
26+
firebase.INTERNAL.extendNamespace({
27+
'INTERNAL': {
28+
'node': {
29+
'localStorage': new Storage(null, { strict: true }),
30+
'sessionStorage': new Storage(null, { strict: true }),
31+
'XMLHttpRequest': XMLHttpRequest
32+
}
33+
}
34+
});
35+
36+
// Export the single instance of firebase
37+
export default firebase;

src/firebase-react-native.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
import firebase from "./app";
18+
import './auth';
19+
import './database';
20+
import './storage';
21+
22+
var AsyncStorage = require('react-native').AsyncStorage;
23+
firebase.INTERNAL.extendNamespace({
24+
'INTERNAL': {
25+
'reactNative': {
26+
'AsyncStorage': AsyncStorage
27+
}
28+
}
29+
});
30+
31+
// Export the single instance of firebase
32+
export default firebase;

src/firebase.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)