Map Preprocessed Code to Supply Code For Your Needs

Map Preprocessed Code to Supply Code For Your Needs

Keep your client-side rule debuggable and readable even with you have combined, minified or put together it. Utilize supply maps to map your supply rule to your put together code.

  • Utilize Source Maps to map code that is minified source rule. Then you’re able to read and debug put together rule with its original supply.
  • Only utilize preprocessors effective at creating supply Maps.
  • Verify that the internet host can provide supply Maps.

Get started doing preprocessors

This informative article explains how exactly to connect with JavaScript Source Maps within the DevTools Sources Panel. For a very first summary of exactly what preprocessors are, the way they can assist and exactly how supply Maps work, mind up to put up CSS & JS Preprocessors.

Work with a supported preprocessor

You should employ a minifier that is with the capacity of creating maps that are source. For the most options that are popular see our preprocessor help area. For an extensive view, russian bride look at supply maps: languages, tools as well as other information wiki page.

The next types of preprocessors can be utilized in combination with supply Maps:

Supply Maps in DevTools Sources panel

Source Maps from preprocessors cause DevTools to load your initial files along with your ones that are minified. After this you make use of the originals to create breakpoints and move through rule. Meanwhile, Chrome is in fact running your minified rule. This provides you the impression of managing a development web web site in manufacturing.

Whenever source that is running in DevTools, you are going to realize that the JavaScript is not put together and you will see most of the specific JavaScript files it references. This really is making use of supply mapping, but behind the scenes really operates the compiled code. Any mistakes, logs and breakpoints will map into the dev rule for awesome debugging! Therefore in place it provides you the impression you are owning a dev web site in manufacturing.

Enable Source Maps in settings

Supply Maps are enabled by default (as of Chrome 39), however if you would like to double-check or allow them, first available DevTools and then click the settings cog . Under Sources, check Enable JavaScript Source Maps. You might additionally check Enable CSS Source Maps.

Debugging with Source Maps

Whenever debugging your rule and Source Maps enabled, supply Maps will show in 2 places:

  1. When you look at the system (the hyperlink to supply ought to be the initial file, perhaps perhaps not the generated one)
  2. Whenever stepping through rule (backlinks when you look at the call stack should start the initial supply file)

DisplayName and@sourceURL

The@sourceURL allows you to make development much easier when working with evals while not part of the source Map spec. This helper appears virtually identical to the //# sourceMappingURL property and it is really mentioned when you look at the Source Map V3 specifications.

By like the after comment that is special your rule, which is evaled, you are able to name evals and inline scripts and styles so they really appear much more logical names in your DevTools.

Navigate for this demo, then:

  • Start the DevTools and go right to the Sources panel.
  • Type in a filename in to the Name your code: input industry.
  • Click the compile switch.
  • An alert will appear with the sum that is evaluated the CoffeeScript supply.

You will now see a new file with the custom filename you entered earlier if you expand the Sources sub-panel. In the event that you double-click to look at this file it’s going to contain the compiled JavaScript for our initial supply. From the line that is last nonetheless, will soon be a // @sourceURL comment indicating just what the initial source file had been. This could significantly assistance with debugging whenever using language abstractions.