Angular-cli: Add option to exclude certain files from sourcemap.

Created on 19 Jun 2018  路  5Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [ ] bug report -> please search issues before submitting
- [x] feature request

Area

- [x] devkit
- [ ] schematics

Versions

Repro steps

The log given by the failure

Desired functionality


I have projects where enabling sourcemaps slows down the ng build operation by a factor of 10. It would be useful to add an option to exclude certain files from source maps generation, or, even better, being able to specify only the files you want to use to generate source map.

This will allow us to specify which file we want to debug without slowing a lot the compilation time.

Mention any other details that might be useful

devkibuild-angular feature

Most helpful comment

This is as well relevant for any Angular workspace containing multiple projects.
Libraries in the workspace fall under the vendor setting as well, so either we take all external source maps and our own libraries, or none at all which kinda is suboptimal.

For this issue the bare minimum would be to at least split "libs" and vendor setting for source maps.

All 5 comments

Hello there,
are there any news on that feature? For better debugging experience I set sourcemap vendor to true. It works, but I get a lot warnings for missing source files.
Is there a way to only set the desired packages to be included in the sourcemaps? Or is it possible to suppress these warnings?

Best regards

This is as well relevant for any Angular workspace containing multiple projects.
Libraries in the workspace fall under the vendor setting as well, so either we take all external source maps and our own libraries, or none at all which kinda is suboptimal.

For this issue the bare minimum would be to at least split "libs" and vendor setting for source maps.

I'm also interested in this feature.
It is really annoying to have a completly messed up console due to dependencies that don't have source maps for all files.

As @klemenoslaj mentioned, there needs to be a way to include our local libraries without including all vendor source maps. We have recently switched to a MonoRepo pattern using angular libraries, and debugging was a nightmare. For debugging to be possible I had to use a custom builder called "@angular-builders/custom-webpack:browser" so I could modify the webpack configuration.

My webpack.config.js file looks like this:

module.exports = config => {
  // Fix for bad source map paths.  I logged bug (https://github.com/angular/angular-cli/issues/19043) and they said is
  // was fixed in Angular 11
  config.context = __dirname;

  // Exclude all vendor source maps except our own.
  // Hopefully they will fix this soon:  https://github.com/angular/angular-cli/issues/11305
  const rule = config.module.rules.find(x => typeof x.loader === 'string' && x.loader.includes('source-map-loader'));
  if (rule) {
    rule.exclude = [
      /(ngfactory|ngstyle)\.js$/, // <== this was already there
      /node_modules\\(?!@sensor)/ // <= exclude everything in node_modules except our stuff
    ];
  }

  // Return config
  return config;
};

We discussed this in our tooling triage meeting. Sourcemaps can definitely take a long time to process and we agree that the current behavior of vendor: false is unintuitive, as most users would expect libraries in a monorepo to apply sourcemaps.

We'll update vendor: false to retain monorepo library sourcemaps but drop all others. This is more intuitive behavior and more in line with what the user probably expected.

Regarding the performance issue, specifying vendor: false with this new behavior is probably enough to get builds to a good place without sacrificing too much in the debugging experience. There may be some edge cases such as very large monorepositories; these can eject to a custom Webpack config if they absolutely need to. We can also revisit adding more fine-grained control of sourcemap generation in the future if this vendor: false tweak is not sufficient for many users.

For now, we'll start with updating vendor: false to keep libraries in a monorepo, and that flag can be used to improve sourcemap performance by dropping all other modules.

Was this page helpful?
0 / 5 - 0 ratings