Skip to content

Commit

Permalink
WIP: generate smaller bundles
Browse files Browse the repository at this point in the history
  • Loading branch information
jsayol committed Jul 8, 2017
1 parent 58fc4c9 commit dd1fd3f
Show file tree
Hide file tree
Showing 4 changed files with 486 additions and 74 deletions.
40 changes: 17 additions & 23 deletions gulp/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ 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) {
function cleanDist(dir) {
return function cleanDistDirectory(done) {
rimraf(`${config.paths.outDir}${ dir ? `/${dir}` : ''}`, done);
}
Expand Down Expand Up @@ -143,22 +144,15 @@ function compileIndvES2015ModulesToBrowser() {
path: path.resolve(__dirname, './dist/browser'),
},
module: {
rules: [{
test: /\.ts(x?)$/,
exclude: /node_modules/,
use: [
babelLoader,
tsLoader
]
}, {
test: /\.js$/,
exclude: /node_modules/,
use: [
babelLoader
]
}]
loaders: [
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader'
}
]
},
plugins: [
new CheckerPlugin(),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: 'firebase-app'
Expand All @@ -172,13 +166,13 @@ function compileIndvES2015ModulesToBrowser() {
},
footer: fileName => {
return isFirebaseApp(fileName) ? `
})();` : `
})().default;` : `
} catch(error) {
throw new Error(
'Cannot instantiate ${fileName} - ' +
'be sure to load firebase-app.js first.'
)
}`
}`
}
}),
new webpack.optimize.UglifyJsPlugin({
Expand Down Expand Up @@ -227,7 +221,7 @@ function copyPackageContents() {
'!./dist/cjs/firebase.js*'
])
.pipe(gulp.dest(`${config.paths.outDir}/package`));

return merge([
copyBrowserCode,
copyCJSCode
Expand All @@ -247,7 +241,7 @@ function compileMetaFiles() {
nyc: null,
babel: null,
});

// Delete all props that are falsy
for (let key in obj) {
if (!obj[key]) delete obj[key];
Expand Down Expand Up @@ -369,17 +363,17 @@ function logFileSize(done) {
};
})
.forEach(obj => console.log(`| ${obj.file} | ${obj.size} | ${obj.gzip} |`));

console.log('\r\n');
done();
}

/**
* GULP TASKS
*
*
* Gulp tasks in Gulp 4.0 are a description of a series of functions.
* The functions are all above and are easier to maintain individually
*
*
* Each "task" is then responsible for wiring up the dep trees itself,
* because of this you have a finer degree of control of the ordering
* of your tasks **and** you can optimize the parallelization of each
Expand Down Expand Up @@ -408,7 +402,7 @@ gulp.task('process:prebuilt', gulp.parallel([
const compileSourceAssets = gulp.series([
compileTypescriptToES2015,
gulp.parallel([
compileIndvES2015ModulesToBrowser,
compileIndvES2015ModulesToBrowser,
compileES2015ToCJS,
])
]);
Expand Down
3 changes: 1 addition & 2 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 Down Expand Up @@ -78,7 +78,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
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

0 comments on commit dd1fd3f

Please sign in to comment.