Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate smaller bundles #94

Merged
merged 2 commits into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ npm-debug.log
/.vscode
/.ts-node
/.idea
/.awcache
14 changes: 13 additions & 1 deletion gulp/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,19 @@ const configObj = {
"browsers": [
"ie >= 9"
]
}
},
}]
]
},
babelWebpack: {
presets: [
["env", {
"modules": false,
"targets": {
"browsers": [
"ie >= 9"
]
},
}]
]
},
Expand Down
55 changes: 24 additions & 31 deletions gulp/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,10 @@ const path = require('path');
const clone = require('gulp-clone');
const webpack = require('webpack');
const webpackStream = require('webpack-stream');
const named = require('vinyl-named');
const sourcemaps = require('gulp-sourcemaps');
const concat = require('gulp-concat');
const replace = require('gulp-replace');
const uglify = require('gulp-uglify');
const gulpFile = require('gulp-file');
const ignore = require('gulp-ignore');
const rimraf = require('rimraf');
const header = require('gulp-header');
const gitRev = require('git-rev-sync');
Expand All @@ -43,6 +40,7 @@ const glob = require('glob');
const fs = require('fs');
const gzipSize = require('gzip-size');
const WrapperPlugin = require('wrapper-webpack-plugin');
const { CheckerPlugin } = require('awesome-typescript-loader');

function cleanDist(dir) {
return function cleanDistDirectory(done) {
Expand Down Expand Up @@ -115,20 +113,6 @@ function compileIndvES2015ModulesToBrowser() {
return pathObj.name === 'firebase-app';
};

const babelLoader = {
loader: 'babel-loader',
options: config.babel
};

const tsLoader = {
loader: 'ts-loader',
options: {
compilerOptions: {
declaration: false
}
}
};

const webpackConfig = {
devtool: 'source-map',
entry: {
Expand All @@ -144,21 +128,18 @@ function compileIndvES2015ModulesToBrowser() {
},
module: {
rules: [{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
babelLoader,
tsLoader
]
}, {
test: /\.js$/,
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
babelLoader
]
loader: 'awesome-typescript-loader',
options: {
useCache: true,
useBabel: true,
babelOptions: config.babelWebpack
}
}]
},
plugins: [
new CheckerPlugin(),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: 'firebase-app'
Expand All @@ -171,8 +152,9 @@ function compileIndvES2015ModulesToBrowser() {
`;
},
footer: fileName => {
// Note: '.default' needed because of https://github.com/babel/babel/issues/2212
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this!

return isFirebaseApp(fileName) ? `
})();` : `
})().default;` : `
} catch(error) {
throw new Error(
'Cannot instantiate ${fileName} - ' +
Expand All @@ -182,13 +164,24 @@ function compileIndvES2015ModulesToBrowser() {
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true
sourceMap: true,
mangle: {
props: {
ignore_quoted: true,
regex: /^_|_$/,
}
},
compress: {
passes: 3,
unsafe: true,
warnings: false,
}
})
],
resolve: {
extensions: ['.ts', '.tsx', '.js']
},
}
};

return gulp.src('src/**/*.ts')
.pipe(webpackStream(webpackConfig, webpack))
Expand Down
5 changes: 1 addition & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"@types/mocha": "^2.2.39",
"@types/node": "^7.0.8",
"@types/sinon": "^1.16.35",
"awesome-typescript-loader": "^3.2.1",
"babel-cli": "^6.23.0",
"babel-core": "^6.24.0",
"babel-loader": "^6.4.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-inline-replace-variables": "^1.2.2",
"babel-plugin-minify-dead-code-elimination": "^0.1.4",
Expand All @@ -53,15 +53,13 @@
"gulp-file": "^0.3.0",
"gulp-header": "^1.8.8",
"gulp-if": "^2.0.2",
"gulp-ignore": "^2.0.2",
"gulp-istanbul": "^1.1.1",
"gulp-mocha": "^4.1.0",
"gulp-rename": "^1.2.2",
"gulp-replace": "^0.5.4",
"gulp-sourcemaps": "^2.4.1",
"gulp-strip-comments": "^2.4.5",
"gulp-typescript": "^3.1.6",
"gulp-uglify": "^2.1.1",
"gzip-size": "^3.0.0",
"husky": "^0.13.3",
"jsdom": "^9.12.0",
Expand All @@ -78,7 +76,6 @@
"shx": "^0.2.2",
"sinon": "^2.1.0",
"through2": "^2.0.3",
"ts-loader": "^2.1.0",
"ts-node": "2.1.1",
"typescript": "^2.2.1",
"validate-commit-msg": "^2.12.1",
Expand Down
29 changes: 14 additions & 15 deletions src/database/core/util/ImmutableTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,25 @@ import { forEach } from '../../../utils/obj';

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

/**
* Singleton empty children collection.
*
* @const
* @type {!SortedMap.<string, !ImmutableTree.<?>>}
*/
const EmptyChildren = (): SortedMap<string, ImmutableTree<null>> => {
if (!emptyChildrenSingleton) {
emptyChildrenSingleton = new SortedMap<string, ImmutableTree<null>>(stringCompare);
}
return emptyChildrenSingleton;
};

/**
* A tree with immutable elements.
*/
export class ImmutableTree<T> {
static Empty = new ImmutableTree<any>(null);

/**
* Singleton empty children collection.
*
* @const
* @type {!SortedMap.<string, !ImmutableTree.<?>>}
* @private
*/
private static get EmptyChildren_(): SortedMap<string, ImmutableTree<null>> {
if (!emptyChildrenSingleton) {
emptyChildrenSingleton = new SortedMap<string, ImmutableTree<null>>(stringCompare);
}
return emptyChildrenSingleton;
}

/**
* @template T
* @param {!Object.<string, !T>} obj
Expand All @@ -60,7 +59,7 @@ export class ImmutableTree<T> {
* @param {SortedMap.<string, !ImmutableTree.<T>>=} children
*/
constructor(public readonly value: T | null,
public readonly children: SortedMap<string, ImmutableTree<T>> = ImmutableTree.EmptyChildren_) {
public readonly children: SortedMap<string, ImmutableTree<T>> = EmptyChildren()) {
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"outDir": "dist/es2015",
"rootDir": "src",
"sourceMap": true,
"target": "es2015",
"target": "es5",
"typeRoots": [
"node_modules/@types"
]
Expand Down
Loading