Skip to content

Commit bcd13ad

Browse files
jsayoljshcrowthe
authored andcommitted
refactor(build): Refactor build process to generate smaller bundles
* fix(build): generate smaller bundles * WIP: address review comments
1 parent 00f9c37 commit bcd13ad

File tree

7 files changed

+523
-141
lines changed

7 files changed

+523
-141
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ npm-debug.log
99
/.vscode
1010
/.ts-node
1111
/.idea
12+
/.awcache

gulp/config.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,19 @@ const configObj = {
5757
"browsers": [
5858
"ie >= 9"
5959
]
60-
}
60+
},
61+
}]
62+
]
63+
},
64+
babelWebpack: {
65+
presets: [
66+
["env", {
67+
"modules": false,
68+
"targets": {
69+
"browsers": [
70+
"ie >= 9"
71+
]
72+
},
6173
}]
6274
]
6375
},

gulp/tasks/build.js

+24-31
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,10 @@ const path = require('path');
2626
const clone = require('gulp-clone');
2727
const webpack = require('webpack');
2828
const webpackStream = require('webpack-stream');
29-
const named = require('vinyl-named');
3029
const sourcemaps = require('gulp-sourcemaps');
3130
const concat = require('gulp-concat');
3231
const replace = require('gulp-replace');
33-
const uglify = require('gulp-uglify');
3432
const gulpFile = require('gulp-file');
35-
const ignore = require('gulp-ignore');
3633
const rimraf = require('rimraf');
3734
const header = require('gulp-header');
3835
const gitRev = require('git-rev-sync');
@@ -43,6 +40,7 @@ const glob = require('glob');
4340
const fs = require('fs');
4441
const gzipSize = require('gzip-size');
4542
const WrapperPlugin = require('wrapper-webpack-plugin');
43+
const { CheckerPlugin } = require('awesome-typescript-loader');
4644

4745
function cleanDist(dir) {
4846
return function cleanDistDirectory(done) {
@@ -115,20 +113,6 @@ function compileIndvES2015ModulesToBrowser() {
115113
return pathObj.name === 'firebase-app';
116114
};
117115

118-
const babelLoader = {
119-
loader: 'babel-loader',
120-
options: config.babel
121-
};
122-
123-
const tsLoader = {
124-
loader: 'ts-loader',
125-
options: {
126-
compilerOptions: {
127-
declaration: false
128-
}
129-
}
130-
};
131-
132116
const webpackConfig = {
133117
devtool: 'source-map',
134118
entry: {
@@ -144,21 +128,18 @@ function compileIndvES2015ModulesToBrowser() {
144128
},
145129
module: {
146130
rules: [{
147-
test: /\.ts(x?)$/,
148-
exclude: /node_modules/,
149-
use: [
150-
babelLoader,
151-
tsLoader
152-
]
153-
}, {
154-
test: /\.js$/,
131+
test: /\.tsx?$/,
155132
exclude: /node_modules/,
156-
use: [
157-
babelLoader
158-
]
133+
loader: 'awesome-typescript-loader',
134+
options: {
135+
useCache: true,
136+
useBabel: true,
137+
babelOptions: config.babelWebpack
138+
}
159139
}]
160140
},
161141
plugins: [
142+
new CheckerPlugin(),
162143
new webpack.optimize.ModuleConcatenationPlugin(),
163144
new webpack.optimize.CommonsChunkPlugin({
164145
name: 'firebase-app'
@@ -171,8 +152,9 @@ function compileIndvES2015ModulesToBrowser() {
171152
`;
172153
},
173154
footer: fileName => {
155+
// Note: '.default' needed because of https://github.com/babel/babel/issues/2212
174156
return isFirebaseApp(fileName) ? `
175-
})();` : `
157+
})().default;` : `
176158
} catch(error) {
177159
throw new Error(
178160
'Cannot instantiate ${fileName} - ' +
@@ -182,13 +164,24 @@ function compileIndvES2015ModulesToBrowser() {
182164
}
183165
}),
184166
new webpack.optimize.UglifyJsPlugin({
185-
sourceMap: true
167+
sourceMap: true,
168+
mangle: {
169+
props: {
170+
ignore_quoted: true,
171+
regex: /^_|_$/,
172+
}
173+
},
174+
compress: {
175+
passes: 3,
176+
unsafe: true,
177+
warnings: false,
178+
}
186179
})
187180
],
188181
resolve: {
189182
extensions: ['.ts', '.tsx', '.js']
190183
},
191-
}
184+
};
192185

193186
return gulp.src('src/**/*.ts')
194187
.pipe(webpackStream(webpackConfig, webpack))

package.json

+1-4
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
"@types/mocha": "^2.2.39",
3131
"@types/node": "^7.0.8",
3232
"@types/sinon": "^1.16.35",
33+
"awesome-typescript-loader": "^3.2.1",
3334
"babel-cli": "^6.23.0",
3435
"babel-core": "^6.24.0",
35-
"babel-loader": "^6.4.0",
3636
"babel-plugin-add-module-exports": "^0.2.1",
3737
"babel-plugin-inline-replace-variables": "^1.2.2",
3838
"babel-plugin-minify-dead-code-elimination": "^0.1.4",
@@ -53,15 +53,13 @@
5353
"gulp-file": "^0.3.0",
5454
"gulp-header": "^1.8.8",
5555
"gulp-if": "^2.0.2",
56-
"gulp-ignore": "^2.0.2",
5756
"gulp-istanbul": "^1.1.1",
5857
"gulp-mocha": "^4.1.0",
5958
"gulp-rename": "^1.2.2",
6059
"gulp-replace": "^0.5.4",
6160
"gulp-sourcemaps": "^2.4.1",
6261
"gulp-strip-comments": "^2.4.5",
6362
"gulp-typescript": "^3.1.6",
64-
"gulp-uglify": "^2.1.1",
6563
"gzip-size": "^3.0.0",
6664
"husky": "^0.13.3",
6765
"jsdom": "^9.12.0",
@@ -78,7 +76,6 @@
7876
"shx": "^0.2.2",
7977
"sinon": "^2.1.0",
8078
"through2": "^2.0.3",
81-
"ts-loader": "^2.1.0",
8279
"ts-node": "2.1.1",
8380
"typescript": "^2.2.1",
8481
"validate-commit-msg": "^2.12.1",

src/database/core/util/ImmutableTree.ts

+14-15
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,25 @@ import { forEach } from '../../../utils/obj';
2121

2222
let emptyChildrenSingleton: SortedMap<string, ImmutableTree<null>>;
2323

24+
/**
25+
* Singleton empty children collection.
26+
*
27+
* @const
28+
* @type {!SortedMap.<string, !ImmutableTree.<?>>}
29+
*/
30+
const EmptyChildren = (): SortedMap<string, ImmutableTree<null>> => {
31+
if (!emptyChildrenSingleton) {
32+
emptyChildrenSingleton = new SortedMap<string, ImmutableTree<null>>(stringCompare);
33+
}
34+
return emptyChildrenSingleton;
35+
};
36+
2437
/**
2538
* A tree with immutable elements.
2639
*/
2740
export class ImmutableTree<T> {
2841
static Empty = new ImmutableTree<any>(null);
2942

30-
/**
31-
* Singleton empty children collection.
32-
*
33-
* @const
34-
* @type {!SortedMap.<string, !ImmutableTree.<?>>}
35-
* @private
36-
*/
37-
private static get EmptyChildren_(): SortedMap<string, ImmutableTree<null>> {
38-
if (!emptyChildrenSingleton) {
39-
emptyChildrenSingleton = new SortedMap<string, ImmutableTree<null>>(stringCompare);
40-
}
41-
return emptyChildrenSingleton;
42-
}
43-
4443
/**
4544
* @template T
4645
* @param {!Object.<string, !T>} obj
@@ -60,7 +59,7 @@ export class ImmutableTree<T> {
6059
* @param {SortedMap.<string, !ImmutableTree.<T>>=} children
6160
*/
6261
constructor(public readonly value: T | null,
63-
public readonly children: SortedMap<string, ImmutableTree<T>> = ImmutableTree.EmptyChildren_) {
62+
public readonly children: SortedMap<string, ImmutableTree<T>> = EmptyChildren()) {
6463
}
6564

6665
/**

tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"outDir": "dist/es2015",
1414
"rootDir": "src",
1515
"sourceMap": true,
16-
"target": "es2015",
16+
"target": "es5",
1717
"typeRoots": [
1818
"node_modules/@types"
1919
]

0 commit comments

Comments
 (0)