4

An exception breakpoint once led me to a render function generated by the Vue template compiler for one of my Vue components.

This striked me as a "Hey, I now understand how this template system works!", but I didn't pay attention to where that was in the webpack tree.

Now I'd like to inspect the code for other components and may be set a breakpoint here and there, but when I browse the active javascript sources in the browser debugger pane, I can't find any of this generated code.

1 Answer 1

2

It looks like the compiled render functions can be found in the sources tree under the . folder of webpack://. It can be a bit tricky to find the right one though because there are multiple files for each .vue file. The other files will contain other bits of the component. The file containing the render function should be pretty obvious when you find it, it should start var render = function() {. For example, in one of my test applications I can see the render function for app.vue at webpack:///./src/app.vue?91e4, though that last part will vary.

If you want to insert a breakpoint for your own component then you can sneak it in via a method. This can also be a quick way to find the right file.

Within the template, make a call to a method, I've called it breakpoint:

{{ breakpoint() }}

Then in the method:

breakpoint () {
  debugger
  return ''
}

You can then walk one level up the stack to see the compiled render function.

Of course you don't necessarily have to use a debugger statement for this. You could just set a browser breakpoint in a suitable method (or introduce one if one doesn't already exist). So long as the method is called within the template it should give you access to the compiled render function.

To set a breakpoint that way you should just need to navigate to the relevant .vue file in the webpack:// section of the sources tree. That file is usually easy to find directly under the webpack:// heading.

Update:

Once you've found the file containing the render function using a breakpoint you can then find the file in the sources tree using 'Reveal in sidebar':

Screenshot of context menu

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

4 Comments

Your breakpoint method works. It points me to webpack:///src/components/MyComp.vue?b080. But this file doesn't appear in the webpack tree (which has other file for the same component).
@Rtbo Initially I thought the files weren't in the Webpack tree but I was looking in the wrong place. In Chrome, once you've found the correct file using a breakpoint, right click on the tab at the top that shows the file name and then select 'Reveal in sidebar'. If that doesn't work then I guess it really isn't in your sources tree.
The problem I have is from using Firefox. In Chrome I can see all the files in the webpack tree, without setting any breakpoint. Thanks for your help.
@Rtbo Agreed, I can't see them in the tree in Firefox. Clicking 'Reveal in Tree' doesn't seem to be able to find them either.

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.