Stop Painful JavaScript Debug and Embrace Intellij with Source Map
I prefer to use IntelliJ to debug JavaScript instead of using browser tools. It’s for sure much more convenient and effective.
Let’s use projects bundled with Browserify and Webpack (no matter the framework).
First, install the JetBrains IDE Support Chrome extension. This will bind the browser debugger environment with IntelliJ in real-time.
Then, let’s open up our IDE and create a JavaScript Debug run configuration. Only two inputs to fill: your app running URL (local or remote) and JS files root directory Remote URL.
Launch the configuration in debug mode and then set a breakpoint in your code (a check mark appears).
Bundlers help to merge sources into a single JS file. By default, there are no ways to perform the reverse action to debug from sources. Except if you ask your bundler to generate a source map file and link it to the bundled file.
// General notation, comment sign must be included!
//# sourceMappingURL=main.js.map// Bundlers notation (to check if source map has been generated)
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ....
Activate source map generation in bundlers is straightforward for both bundlers. Enable debug mode in Browserify or set devtool value in Webpack configuration.
Webpack can generate source map for a production environment in an optimized way.
The debug configuration in IntelliJ is a bit different with webpack-dev-server, bundled files are deployed on webpack:///.
To debug the app, the project Remote URL must be set to this value (do not omit the dot). Note the JS files root directory Remote URL still on localhost.
References about this topic
If you encounter any troubles with debug configuration and Webpack, take a look at this JetBrains post:
For complete information about how source map works read Mozilla documentation. To see what source map file looks like, read this blog post.
Thank you for reading, I hope you enjoyed reading this article and it will help
If you found this article useful, please click on the 👏 button a few times to make others find the article and to show your support! 👊
Don’t forget to follow me to get notified of my upcoming articles 🙏
Check out my Other Articles
➥ JavaScript
- How to Improve Your JavaScript Skills by Writing Your Own Web Development Framework 💪
- Common Mistakes to Avoid While Working with Vue.js
➥ React for beginners series
Originally published at www.linkedin.com on January 19, 2018.