Skip to content

Commit dd1fd3f

Browse files
committed
WIP: generate smaller bundles
1 parent 58fc4c9 commit dd1fd3f

File tree

4 files changed

+486
-74
lines changed

4 files changed

+486
-74
lines changed

gulp/tasks/build.js

+17-23
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@ const glob = require('glob');
4343
const fs = require('fs');
4444
const gzipSize = require('gzip-size');
4545
const WrapperPlugin = require('wrapper-webpack-plugin');
46+
const { CheckerPlugin } = require('awesome-typescript-loader');
4647

47-
function cleanDist(dir) {
48+
function cleanDist(dir) {
4849
return function cleanDistDirectory(done) {
4950
rimraf(`${config.paths.outDir}${ dir ? `/${dir}` : ''}`, done);
5051
}
@@ -143,22 +144,15 @@ function compileIndvES2015ModulesToBrowser() {
143144
path: path.resolve(__dirname, './dist/browser'),
144145
},
145146
module: {
146-
rules: [{
147-
test: /\.ts(x?)$/,
148-
exclude: /node_modules/,
149-
use: [
150-
babelLoader,
151-
tsLoader
152-
]
153-
}, {
154-
test: /\.js$/,
155-
exclude: /node_modules/,
156-
use: [
157-
babelLoader
158-
]
159-
}]
147+
loaders: [
148+
{
149+
test: /\.tsx?$/,
150+
loader: 'awesome-typescript-loader'
151+
}
152+
]
160153
},
161154
plugins: [
155+
new CheckerPlugin(),
162156
new webpack.optimize.ModuleConcatenationPlugin(),
163157
new webpack.optimize.CommonsChunkPlugin({
164158
name: 'firebase-app'
@@ -172,13 +166,13 @@ function compileIndvES2015ModulesToBrowser() {
172166
},
173167
footer: fileName => {
174168
return isFirebaseApp(fileName) ? `
175-
})();` : `
169+
})().default;` : `
176170
} catch(error) {
177171
throw new Error(
178172
'Cannot instantiate ${fileName} - ' +
179173
'be sure to load firebase-app.js first.'
180174
)
181-
}`
175+
}`
182176
}
183177
}),
184178
new webpack.optimize.UglifyJsPlugin({
@@ -227,7 +221,7 @@ function copyPackageContents() {
227221
'!./dist/cjs/firebase.js*'
228222
])
229223
.pipe(gulp.dest(`${config.paths.outDir}/package`));
230-
224+
231225
return merge([
232226
copyBrowserCode,
233227
copyCJSCode
@@ -247,7 +241,7 @@ function compileMetaFiles() {
247241
nyc: null,
248242
babel: null,
249243
});
250-
244+
251245
// Delete all props that are falsy
252246
for (let key in obj) {
253247
if (!obj[key]) delete obj[key];
@@ -369,17 +363,17 @@ function logFileSize(done) {
369363
};
370364
})
371365
.forEach(obj => console.log(`| ${obj.file} | ${obj.size} | ${obj.gzip} |`));
372-
366+
373367
console.log('\r\n');
374368
done();
375369
}
376370

377371
/**
378372
* GULP TASKS
379-
*
373+
*
380374
* Gulp tasks in Gulp 4.0 are a description of a series of functions.
381375
* The functions are all above and are easier to maintain individually
382-
*
376+
*
383377
* Each "task" is then responsible for wiring up the dep trees itself,
384378
* because of this you have a finer degree of control of the ordering
385379
* of your tasks **and** you can optimize the parallelization of each
@@ -408,7 +402,7 @@ gulp.task('process:prebuilt', gulp.parallel([
408402
const compileSourceAssets = gulp.series([
409403
compileTypescriptToES2015,
410404
gulp.parallel([
411-
compileIndvES2015ModulesToBrowser,
405+
compileIndvES2015ModulesToBrowser,
412406
compileES2015ToCJS,
413407
])
414408
]);

package.json

+1-2
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",
@@ -78,7 +78,6 @@
7878
"shx": "^0.2.2",
7979
"sinon": "^2.1.0",
8080
"through2": "^2.0.3",
81-
"ts-loader": "^2.1.0",
8281
"ts-node": "2.1.1",
8382
"typescript": "^2.2.1",
8483
"validate-commit-msg": "^2.12.1",

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)