问题描述
错误:
HTML Webpack 插件: 错误:webpack://webpack/data:text/javascript,webpack_public_path_=webpack_base_uri=_htmlWebpackPl uginPublicPath;?:2 webpack_require.p = webpack_base_uri = htmlWebpackPluginPublicPath; ^
ReferenceError:webpack_base_uri 未定义
javascript,webpack_public_path_=webpack_base_uri=htmlWebpackPluginPublicPath;?:2 eval webpack://webpack/data:text/javascript,webpack_public_path=webpack_base_uri=_htmlWebpackPluginP ublicPath;?:2:46
-
index.html:30 Object.data:text/javascript,webpack_public_path = webpack_base_uri = htmlWebpackPlug inPublicPath; C:/Users/Ymtx/Desktop/vue/webpack/src/index.html:30:1
-
index.html:53 webpack_require C:/Users/Ymtx/Desktop/vue/webpack/src/index.html:53:41
我不知道为什么会发生这种情况,我已经阅读了很多博客,但关于它的博客很少。我确实想用它来做。请帮助我。
代码↓
var webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const htmlPlugin = new HtmlWebpackPlugin({
template:'./src/index.html',filename:'index.html',})
module.exports = {
mode:"development",entry:path.join(__dirname,'./src/index.js'),output:{
path:path.join(__dirname,'./dist'),filename:'bundle.js'
},plugins:[htmlPlugin]
}
package.json
{
"name": "webpack","version": "1.0.0","description": "","main": "index.js","scripts": {
"test": "echo \"Error: no test specified\" && exit 1","dev": "webpack-dev-server --open --host --127.0.0.1 --port 8888"
},"keywords": [],"author": "","license": "ISC","dependencies": {
"jquery": "^3.6.0"
},"devDependencies": {
"css-loader": "^5.2.4","html-webpack-plugin": "^5.3.1","style-loader": "^2.0.0","vue": "^2.6.12","webpack": "^4.46.0","webpack-cli": "^3.3.12","webpack-dev-server": "^3.1.14"
}
}
解决方法
尝试在 webpack 配置中添加插件:
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('development')
})
],