我对webpack还很陌生,在配置它以生成必要的源代码Map时遇到了一些麻烦。在devtools中它说
检测到源Map
但它显示的是bundle,而不是原始代码:
下面是我的webpack.config.js:
module.exports = {
entry: [
'webpack-dev-server/client?http://localhost:8080/',
'webpack/hot/dev-server',
"./src/index.js"
],
output: {
filename: 'bundle.js',
path: '/',
},
debug: true,
devtool: 'source-map',
resolve: {
extensions: ['', '.jsx', '.scss', '.js', '.json']
},
module: {
loaders: [
{
test: /(\.js|\.jsx)$/,
exclude: /node_modules/,
loaders: ['react-hot','babel']
},
{
test: /\.scss$/,
exclude: /node_modules/,
loaders: ["style", "css?sourceMap", "sass?sourceMap"]
}
]
},
devServer: { hot: true },
plugins: [ new webpack.HotModuleReplacementPlugin() ],
inline: true,
progress: true,
colors: true
};
这是我的包。json:
{
"name": "react-template",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"dev:test": "./node_modules/.bin/webpack --config webpack.test.config.js",
"test:bundle": "./node_modules/.bin/tape test/bundle.js",
"dev:serve": "./node_modules/.bin/webpack-dev-server --config webpack.development.config.js"
},
"devDependencies": {
"babel-loader": "^6.2.1",
"babel-preset-es2015": "^6.3.13",
"babel-preset-react": "^6.3.13",
"babel-preset-stage-0": "^6.3.13",
"css-loader": "^0.23.1",
"node-sass": "^3.8.0",
"on-build-webpack": "^0.1.0",
"react": "^0.14.6",
"react-dom": "^0.14.6",
"react-hot-loader": "^1.3.0",
"sass-loader": "^3.2.1",
"style-loader": "^0.13.0",
"tape": "^4.4.0",
"webpack": "^1.12.12",
"webpack-dev-server": "^1.14.1"
}
}
6条答案
按热度按时间ebdffaop1#
在
bundle.js
中,您将看到原始的转译webpack包-这是正常的行为。打开
webpack://
,您将看到您的项目文件。s4chpxco2#
在webpack.config.js文件中添加以下内容:
你可以在webpack网站上找到关于它的详细信息:https://webpack.js.org/configuration/devtool/
另外,请从webpack网站上找到附加的sourcemap部分的屏幕截图。
kiayqfof3#
确保在
npm
构建脚本中包含--mode development
,webpack.config.js
mnowg1ta4#
我遇到的问题是我的
nginx
配置。我的nginx配置为源Map文件抛出404,因为它无法识别要查找的.map
文件。因此,除了.js|.css
之外,还添加了.map
,并且它是固定的。9q78igpj5#
对我来说,问题是我的html中有一个特殊的字符“ß”:
已将默认值更改为
"Gerwigstraße 22, 76131 Karlsruhe"
,源Map再次正常工作。xzlaal3s6#
如果'source-map'不起作用,您可以尝试'inline-source-map':
或者如果你仍然想使用'source-map',你可以尝试在你的插件中添加这一行:
],