1

I want to debug the typescript source code of angular2. But I can not find source map file in bundles directory.So how angular2 creates bundles directory? And Can I generate it myself?

enter image description here

1
  • add sourceMap: true in your tsconfig.json Commented Apr 5, 2016 at 12:04

1 Answer 1

1

You could configure SystemJS to load Angular2 modules from separate files instead of the bundled ones.

<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>

<script>
  System.config({
    defaultJSExtensions: true,
    map: {
      angular2: 'node_modules/angular2',
      rxjs: 'node_modules/rxjs'
    },
    packages: {
      app: {
        defaultExtension: 'js',
        format: 'register'
      },
      angular2: {
        defaultExtension: 'js',
      }
    }
  });
  System.import('app/boot')
        .then(null, console.error.bind(console));
</script>

Source maps are embedded in JS files in the node_modules/angular2 folder this way:

//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjoz(...)

This way you will be able to put breakpoints into Angular2 TypeScript files using DevTools.

Notice that the application load will be longer with this approach...

See this article for more details:

Sign up to request clarification or add additional context in comments.

4 Comments

Ii does not work! Can you show me in plunker? Thanks a lot!
What do you exactly mean by "it does not work"? ;-) You can't load the application or you can't set breakpoints in TypeScript files?
It's difficult to explain within an answer. So I created an article on the medium with screenshots: medium.com/@ttemplier/…. Hope it will answer your question ;-)
@ThierryTemplier, have you tried that approach on the newest npm package that doesn't contain sources? I've posted the question, appreciate any feedback

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.