Skip to content

@ngtools/webpack - enable sourceMap generates different build #14617

Closed
@sod

Description

@sod

@ngtools/webpack produces different javascript output if you toggle the sourceMap setting. With source maps enabled, the compiler seems to include imports, that shouldn't be there.

Angular: 8.0.0 (but issue is present in 7.2.x as well)
Reproduction: https://github.com/sod/issue-ngtools-14617

Compare both dist-* folders. The only difference in the build is the --source-map flag. In one build the chunk big-dependency is missing and was inlined by webpack.

You can try to build it yourself with either one:

ng build --prod --aot --build-optimizer --source-map
ng build --prod --aot --build-optimizer

If you watch the output with --source-map of the ngtools/webpack loader in https://github.com/angular/angular-cli/blob/master/packages/ngtools/webpack/src/loader.ts#L104, I see for the file https://github.com/sod/issue-ngtools-14617/blob/master/src/app/lorem/lorem.service.ts this output:

import { BigDependencyOptions } from 'src/app/lorem/big-dependency';
import * as i0 from "@angular/core";
var bigDependencyLoader = function () { return import(/* webpackChunkName: "big-dependency" */ '../lorem/big-dependency'); };
var ɵ0 = bigDependencyLoader;
var LoremService = /** @class */ (function () {
    function LoremService() {
    }
    LoremService.prototype.load = function (options) {
        return bigDependencyLoader().then(function (m) { return new m.BigDependency().setOptions(options); });
    };
    LoremService.ngInjectableDef = i0.ɵɵdefineInjectable({ factory: function LoremService_Factory() { return new LoremService(); }, token: LoremService, providedIn: "root" });
    return LoremService;
}());
export { LoremService };
export { ɵ0 };

BigDependencyOptions is an Interface and only used as a type, that import should not be visible in javascript. If you throw the source into typescriptlang, you see that tsc wouldn't include that import as well.

We use an error reporting tool where we can upload the source maps to get better reports. But this behavior increases our build by ~100kb so we compile without source maps right now.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions