Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug "webpack.config.js" file?

Tags:

I want to debug the "webpack.config.js" file, not the application using "devtool: 'source-map'". I want the webpack configuration file to be debuged. Is there any option?

like image 606
Ignatius Andrew Avatar asked Dec 30 '16 13:12

Ignatius Andrew


People also ask

How do I debug a webpack config file?

Click the "inspect" link under each script to open a dedicated debugger or the Open dedicated DevTools for Node link for a session that will connect automatically. You can also check out the NiM extension, a handy Chrome plugin that will automatically open a DevTools tab every time you --inspect a script.

How do I debug JavaScript with webpack?

Webpack provides the devtool option to enhance debugging in the developer tool just creating a source map of the bundled file for you. This option can be used from the command line or used in your webpack. config. js configuration file.

How do I debug a JavaScript bundle?

Open any web site. Open developer tools in chrome by pressing F12 /Ctrl + Shift + I/ right-click anywhere inside the web page and select Inspect/Inspect Element which will be mostly the last option. Go to Sources tab in developer tools and open any minified JS which you want to debug as shown in the image.

Where is my webpack config js file?

The webpack configuration file webpack. config. js is the file that contains all the configuration, plugins, loaders, etc. to build the JavaScript part of the NativeScript application. The file is located at the root of the NativeScript application.


1 Answers

Simply run webpack.js in debug mode using nodejs. You can run the following on your terminal (assuming you are already in the directory with your node_modules present):

node --inspect node_modules/webpack/bin/webpack.js --colors 

I also found the VSCode debugger very intuitive for debugging when i was developing my own webpack loader. If you use VS Code you can have your launch.json have the following configuration:

{         "type": "node",          "request": "attach",         "name": "Attach",         "port": 5858 } 

Then run the node inspector with the following command:

node --inspect-brk=5858 node_modules/webpack/bin/webpack.js --colors 

Finally run the debug configuration by going to the debug tab, pick your configuration at the top and then press the run configuration button.

like image 150
asulaiman Avatar answered Sep 28 '22 02:09

asulaiman