【发布时间】:2020-07-10 09:46:20
【问题描述】:
我正在尝试设置一个简单的 html/Js 页面。
我已经安装了 webpack 和 babel。我已经用“build”和“start”脚本配置了 package.json 文件。
页面运行良好,但每次执行“npm run start”命令时都会出现警告:“DevTools 无法解析 SourceMap:webpack:///node_modules/sockjs-client/dist/sockjs.js.map”而且我无法在 Chome Devtools 中调试我的代码
package.json:
{
"name": "my-proyect",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "webpack-dev-server --config ./webpack.config.js --mode development",
"build": "webpack --config ./webpack.config.js --mode production",
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.0",
"babel-loader": "^8.1.0",
"html-webpack-plugin": "^4.0.3",
"webpack": "^4.42.1",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.10.3"
}
}
webpack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin')
module.exports = {
// 1
entry: './src/index.js',
///////// BABEL ///////////////
module: {
rules: [
{
test: /\.(js)$/,
exclude: /node_modules/,
use: ['babel-loader']
}
]
},
resolve: {
extensions: ['*', '.js']
},
////////////////////////
///////// Plugins ///////////
plugins: [
new HtmlWebpackPlugin({
title: 'Hello Webpack bundled JavaScript Project',
template: './src/index.html'
})
],
// 2
output: {
path: __dirname + '/dist',
publicPath: '/',
filename: 'bundle.js'
},
// 3
devServer: {
contentBase: './dist'
}
};
如果有人能指导我解决这个问题,我将不胜感激。
问候。
【问题讨论】:
标签: javascript webpack google-chrome-devtools babeljs