【发布时间】:2018-04-30 17:52:28
【问题描述】:
在我决定发布这个问题之前,我做了很多事情作为背景调查。 所以,我的问题是:
- 我使用 webpack v4.6.0 和 webpack-dev-server v3.1.3 - 它们一起工作得很好,但现在我正在尝试为我的应用程序设置源映射,devtool option 似乎不起作用。
至少对我来说,我已经尝试并测试了列表中的每个选项:
-
Webpack 4 - Sourcemaps:
这个问题表明
devtool: 'source-map'应该开箱即用,但对我来说不是这样 -
how to make webpack sourcemap to original files :将
devtoolModuleFilenameTemplate: info =>'file://' + path.resolve(info.absoluteResourcePath).replace(/\\/g, '/')添加到我的输出配置并没有太大帮助,而不是client.js 它为我显示index.js 虽然 - https://github.com/webpack/webpack/issues/6400:这不是对我的问题的准确描述,通过尝试这里的方法似乎也对我没有帮助
- 我尝试使用
webpack.SourceMapDevToolPlugin,但它也不适用于我的设置,即使我删除了 devtools 或将它们设置为 false - 我这里没有使用 UglifyJS 插件
- 我知道 webpack-dev-server 现在正在维护中,所以我尝试了 webpack-serve,但似乎 source maps 也无法使用它
- 我也尝试过source-map-support包,但也没有运气,和here有类似的情况:
您是否知道该问题是否会由一些 PR 解决,或者您是否尝试过自己解决?任何提示或帮助表示赞赏!
我希望得到此处所述的输出,in blogpost,其中包含指向我的文件和原始文件代码的直接链接。
我的 webpack.js
// webpack v4.6.0
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const WebpackMd5Hash = require('webpack-md5-hash');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const stylish = require('eslint/lib/formatters/stylish');
const webpack = require('webpack');
module.exports = {
entry: { main: './src/index.js' },
output: {
devtoolModuleFilenameTemplate: info =>
'file://' + path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
path: path.resolve(__dirname, 'dist'),
filename: '[name].[hash].js'
},
devtool: 'source-map',
devServer: {
contentBase: './dist',
hot: true
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
formatter: stylish
}
}
]
},
plugins: [
// new webpack.SourceMapDevToolPlugin({
// filename: '[file].map',
// moduleFilenameTemplate: undefined,
// fallbackModuleFilenameTemplate: undefined,
// append: null,
// module: true,
// columns: true,
// lineToLine: false,
// noSources: false,
// namespace: ''
// }),
new CleanWebpackPlugin('dist', {}),
new HtmlWebpackPlugin({
inject: false,
hash: true,
template: './src/index.html',
filename: 'index.html'
}),
new WebpackMd5Hash(),
new webpack.NamedModulesPlugin(),
new webpack.HotModuleReplacementPlugin()
]
};
我的 package.json
{
"name": "post",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"storybook": "start-storybook -p 9001 -c .storybook",
"dev": "webpack-dev-server --mode development --open",
"build": "webpack --mode production"
},
"author": "",
"license": "ISC",
"devDependencies": {
"@storybook/addon-actions": "^3.4.3",
"@storybook/react": "v4.0.0-alpha.4",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.6.1",
"babel-preset-react": "^6.24.1",
"babel-runtime": "^6.26.0",
"clean-webpack-plugin": "^0.1.19",
"eslint": "^4.19.1",
"eslint-config-prettier": "^2.9.0",
"eslint-loader": "^2.0.0",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-react": "^7.7.0",
"html-webpack-plugin": "^3.2.0",
"prettier": "^1.12.1",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"webpack": "v4.6.0",
"webpack-cli": "^2.0.13",
"webpack-dev-server": "v3.1.3",
"webpack-md5-hash": "0.0.6",
"webpack-serve": "^0.3.1"
},
"dependencies": {
"source-map-support": "^0.5.5"
}
}
编辑:
我看到了一个类似的问题here,但似乎没有人回答。 错误是故意犯的! 这不仅适用于 linting 错误,还适用于我的应用程序的每个错误。 Here is a link to my GITHUB repo: https://github.com/marharyta/webpack-fast-development
更新 01.05.2018
我创建了另一个具有更清洁设置的存储库:https://github.com/marharyta/webpack-4.6.0-test 并详细说明我是如何到达这里的:https://medium.com/p/79fb676417f4/edit webpack 贡献者给出了一些建议,但对我仍然不起作用:https://github.com/marharyta/webpack-4.6.0-test/issues/1
更新 02.05.2018
经过长时间的调查,我在下面发布了我的答案。问题是 ESLint 可能还有一些模式标记,因为我必须使用 CLI 方式进行操作。 我在 ESLint 加载器中也存在问题:https://github.com/webpack-contrib/eslint-loader/issues/227 我还在这里创建了一个带有更详细描述的帖子:https://medium.com/@riittagirl/how-to-solve-webpack-problems-the-practical-case-79fb676417f4
【问题讨论】:
标签: reactjs npm webpack webpack-dev-server source-maps