angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

bundle size

Open coryrylan opened this issue 9 years ago • 9 comments

Please provide us with the following information:

OS?

Mac Sierra

Versions.

Beta 25.5

Mention any other details that might be useful.

This is not a bug but wanted to touch base on the output of the bundles in the CLI projects. I hooked the https://github.com/th0r/webpack-bundle-analyzer into the CLI to see what the bundles looked like for a brand new Hello World project.

Right now it looks like Angular itself is around 134kb gziped. This is not including its Rx, Zone or CoreJS dependencies. I noticed the Angular part of the bundle is rather large and didn't know if there were any benchmarks of what we hope the target bundle size to be. Not sure if this is actionable on the tooling/CLI or something that needs to be filed with the Core project.

Other bundle size references: http://www.syntaxsuccess.com/viewarticle/size-of-angular-applications

screen shot 2017-01-14 at 5 17 20 pm

Repro steps.

  1. ng new test-project npm install --save-dev webpack-bundle-analyzer npm install --save-dev webpack-stats-plugin ng build --prod --aot --no-sourcemap

  2. Then replace node_modules/angular-cli/models/webpack.config.js with the following altered webpack config:

// 1) `ng new test-project` 
//     `npm install --save-dev webpack-bundle-analyzer`
//     `npm install --save-dev webpack-stats-plugin`
//     `ng build --prod --aot --no-sourcemap`

// 2) Then replace `node_modules/angular-cli/models/webpack.config.js`
//    with this following altered webpack config:

// 3) `cd dist && webpack-bundle-analyzer stats.json`

// 4) All altered lines are marked with BUNDLE_HACK

"use strict";
var webpack_build_typescript_1 = require('./webpack-build-typescript');
var webpackMerge = require('webpack-merge');
var config_1 = require('./config');
var webpack_build_common_1 = require('./webpack-build-common');
var webpack_build_development_1 = require('./webpack-build-development');
var webpack_build_production_1 = require('./webpack-build-production');
var webpack_build_mobile_1 = require('./webpack-build-mobile');
var StatsWriterPlugin = require("webpack-stats-plugin").StatsWriterPlugin; // BUNDLE_HACK
var NgCliWebpackConfig = (function () {
    function NgCliWebpackConfig(ngCliProject, target, environment, outputDir, baseHref, i18nFile, i18nFormat, locale, isAoT, sourcemap, vendorChunk, verbose, progress, deployUrl, outputHashing, extractCss) {
        if (isAoT === void 0) { isAoT = false; }
        if (sourcemap === void 0) { sourcemap = true; }
        if (vendorChunk === void 0) { vendorChunk = false; }
        if (verbose === void 0) { verbose = false; }
        if (progress === void 0) { progress = true; }
        if (extractCss === void 0) { extractCss = true; }
        this.ngCliProject = ngCliProject;
        this.target = target;
        this.environment = environment;
        var appConfig = config_1.CliConfig.fromProject().config.apps[0];
        var projectRoot = this.ngCliProject.root;
        appConfig.outDir = outputDir || appConfig.outDir;
        appConfig.deployUrl = deployUrl || appConfig.deployUrl;
        var baseConfig = webpack_build_common_1.getWebpackCommonConfig(projectRoot, environment, appConfig, baseHref, sourcemap, vendorChunk, verbose, progress, outputHashing, extractCss);
        var targetConfigPartial = this.getTargetConfig(projectRoot, appConfig, sourcemap, verbose);
        if (appConfig.mobile) {
            var mobileConfigPartial = webpack_build_mobile_1.getWebpackMobileConfigPartial(projectRoot, appConfig);
            var mobileProdConfigPartial = webpack_build_mobile_1.getWebpackMobileProdConfigPartial(projectRoot, appConfig);
            baseConfig = webpackMerge(baseConfig, mobileConfigPartial);
            if (this.target == 'production') {
                targetConfigPartial = webpackMerge(targetConfigPartial, mobileProdConfigPartial);
            }
        }
        var config = webpackMerge(baseConfig, targetConfigPartial);
        if (appConfig.main) {
            var typescriptConfigPartial = isAoT
                ? webpack_build_typescript_1.getWebpackAotConfigPartial(projectRoot, appConfig, i18nFile, i18nFormat, locale)
                : webpack_build_typescript_1.getWebpackNonAotConfigPartial(projectRoot, appConfig);
            config = webpackMerge(config, typescriptConfigPartial);
        }
        this.config = config;
    }
    NgCliWebpackConfig.prototype.getTargetConfig = function (projectRoot, appConfig, sourcemap, verbose) {
        var statWriter = new StatsWriterPlugin({
           fields: null,
		       stats: {chunkModules: true}
        });
		
		switch (this.target) {
            case 'development':
                var data = webpack_build_development_1.getWebpackDevConfigPartial(projectRoot, appConfig); // BUNDLE_HACK
				if(typeof(data.plugins) === 'undefined') {
                 data['plugins'] = [];
                }
                data.plugins.push(statWriter);
				return data;
            case 'production':
                var data = webpack_build_production_1.getWebpackProdConfigPartial(projectRoot, appConfig, sourcemap, verbose); // BUNDLE_HACK
				if(typeof(data.plugins) === 'undefined') {
                 data['plugins'] = [];
                }
                data.plugins.push(statWriter);
				return data;
			default:
                throw new Error("Invalid build target. Only 'development' and 'production' are available.");
        }
    };
    return NgCliWebpackConfig;
}());
exports.NgCliWebpackConfig = NgCliWebpackConfig;
//# sourceMappingURL=/Users/hansl/Sources/angular-cli/packages/angular-cli/models/webpack-config.js.map
  1. cd dist && webpack-bundle-analyzer stats.json

coryrylan avatar Jan 14 '17 23:01 coryrylan

@splintercode Am I wrong in assuming that you should run ng build --prod --aot --no-sourcemap inbetween step 2 and 3 rather than doing in in step 1?

Markus-ipse avatar Jan 17 '17 17:01 Markus-ipse

@Markus-ipse Just updated the comment. Thanks!

coryrylan avatar Jan 18 '17 02:01 coryrylan

Yeah!

glebmachine avatar Jan 22 '17 09:01 glebmachine

@splintercode , hi. With plain angular-cli beta26 (not changing any webpack config, only ng new + ng build --prod --aot), I got following:

83,794 polyfills.2acd84dcea45ba18d978.bundle.js
26,640 polyfills.2acd84dcea45ba18d978.bundle.js.gz
369,365 vendor.da20fa58a1097b10dc45.bundle.js
74,317 vendor.da20fa58a1097b10dc45.bundle.js.gz

@angular/modules takes up all the vendor.bundle, with unzipped size as similar to yours 343k, while the gzipped size is only around 73k, not 134k.

rxjs-space avatar Jan 23 '17 05:01 rxjs-space

I'm going to close this issue in favor of https://github.com/angular/angular-cli/issues/4172, mostly because I already answered there.

filipesilva avatar Jan 24 '17 16:01 filipesilva

@filipesilva can you add bundle analyzer by default into angular-cli? This is great tool to inspect your bundles and chunks.

glebmachine avatar Jan 25 '17 09:01 glebmachine

@glebmachine you can use source-map-explore mentioned in #4172, it doesn't require any change to angular-cli files

Markus-ipse avatar Jan 25 '17 12:01 Markus-ipse

Got it, thank you!)

glebmachine avatar Jan 25 '17 12:01 glebmachine

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.