-
Notifications
You must be signed in to change notification settings - Fork 994
Generate smaller bundles #94
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,3 +9,4 @@ npm-debug.log | |
| /.vscode | ||
| /.ts-node | ||
| /.idea | ||
| /.awcache | ||
| Original file line number | Diff line number | Diff line change | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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'); | |||||||||||||||||
|
|
@@ -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) { | |||||||||||||||||
|
|
@@ -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: { | |||||||||||||||||
|
|
@@ -144,21 +128,23 @@ 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.DefinePlugin({ | |||||||||||||||||
| 'process.env': { | |||||||||||||||||
| 'NODE_ENV': JSON.stringify('production') | |||||||||||||||||
| } | |||||||||||||||||
| }), | |||||||||||||||||
| new webpack.optimize.ModuleConcatenationPlugin(), | |||||||||||||||||
| new webpack.optimize.CommonsChunkPlugin({ | |||||||||||||||||
| name: 'firebase-app' | |||||||||||||||||
|
|
@@ -171,8 +157,9 @@ function compileIndvES2015ModulesToBrowser() { | ||||||||||||||||
| `; | |||||||||||||||||
| }, | |||||||||||||||||
| footer: fileName => { | |||||||||||||||||
| // Note: '.default' needed because of https://github.com/babel/babel/issues/2212 | |||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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} - ' + | |||||||||||||||||
|
|
@@ -182,13 +169,24 @@ function compileIndvES2015ModulesToBrowser() { | ||||||||||||||||
| } | |||||||||||||||||
| }), | |||||||||||||||||
| new webpack.optimize.UglifyJsPlugin({ | |||||||||||||||||
| sourceMap: true | |||||||||||||||||
| sourceMap: true, | |||||||||||||||||
| mangle: { | |||||||||||||||||
| props: { | |||||||||||||||||
| ignore_quoted: true, | |||||||||||||||||
| regex: /_$/, | |||||||||||||||||
|
|||||||||||||||||
| File | Suffix Only Regex | Prefix + Suffix Regex |
|---|---|---|
| firebase-app.js | 16.14 KB (5.61 KB) | 15.7 KB (5.55 KB) |
| firebase-database.js | 166.16 KB (45.55 KB) | 165.8 KB (45.52 KB) |
| firebase-messaging.js | 18.22 KB (5.59 KB) | 18.2 KB (5.59 KB) |
| firebase.js | 371.3 KB (108.1 KB) | 370.49 KB (108.02 KB) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! The SDK code only uses _ as a suffix but other imported dependencies must be using it as a prefix too. I'll update it with this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I diff'ed doing the compression w/ and w/o this. For me I was seeing a little bit better results compiling database without this.
Size Comparison
webpack.DefinePluginwebpack.DefinePluginThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I'll get rid of it then.