JavaScript Answers

How to remove webpack:// from sources in the browser?

Spread the love

When we see webpack:// in the sources tab of our browser’s developer tools, it means that our JavaScript source files are being served directly from Webpack’s development server.

This is a common occurrence during development with Vue.js and other modern JavaScript frameworks.

To remove webpack:// from the sources and see the original file paths, we need to configure Webpack to generate source maps with the devtool option set to a value that preserves the original file paths.

In our Webpack configuration file (webpack.config.js or vue.config.js if we are using Vue CLI), we should set the devtool option to a value like 'source-map' or 'cheap-source-map'.

Here’s how we can do it:

// webpack.config.js or vue.config.js

module.exports = {
  // other configurations...
  devtool: 'source-map' // or 'cheap-source-map'

By setting devtool to 'source-map', Webpack will generate source maps that preserve the original file paths.

After making this change and rebuilding our project, we should see the original file paths in our browser’s developer tools instead of webpack://.

Remember that generating source maps can impact build performance and increase the size of our build output, so it’s a good practice to use a more efficient option like 'cheap-source-map' in development.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *