I\'m pretty new to webpack and having some trouble configuring it to produce the necessary source maps. In the devtools it says
Source Map detected
The issue I was facing was in my nginx
configuration. My nginx configuration was throwing 404 for the source map files, because it couldn't identify the .map
files where to look for. So added .map
also in addition to .js|.css
and it was fixed.
location ~* \.(?:css|js|map)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
In bundle.js
you will see original transpiled webpack bundle - this is normal behaviour.
Open webpack://
and you will see your project files.
Please add in you webpack.config.js file the following`
devtool: "#inline-source-map",
You can find clear information about it from the site of webpack` https://webpack.github.io/docs/configuration.html
Also please find attached screenshot of sourcemap part, from webpack site.
Make sure you have --mode development
in your npm
build script,
{
"name": "test",
"version": "1.0.1",
"description": "",
"scripts": {
"build": "webpack",
"start": "webpack-dev-server --mode development --open"
"test": "echo \"Error: no test specified\" && exit 1",
},
"author": "",
"license": "",
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.5",
"babel-preset-env": "^1.7.0",
"webpack": "^4.19.1",
"webpack-cli": "^3.1.0",
"webpack-dev-server": "^3.1.8"
},
"dependencies": {}
}
webpack.config.js
const path = require('path');
var webpack = require('webpack');
module.exports = {
entry: './src/web.js',
devtool: 'inline-source-map',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist')
},
mode: 'development',
module: {
rules: [{
test: /\.js$/,
exclude: /(node_modules)/,
use: {
loader: "babel-loader",
options: {
presets: ["babel-preset-env"]
}
}
}]
},
devServer: {
inline: true,
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 9000,
watchOptions: {
index: 'index.html',
open: true,
poll: true,
watchContentBase: true
}
},
watch: true,
watchOptions: {
aggregateTimeout: 500,
ignored: /node_modules/,
poll: 3000
}
}