发现服务器访问的是dist目录下的index.html,不是应该访问内存中编译后的文件吗?干嘛要访问我本地实实在在的文件。
localhost:8080打开后,就显示listDirectory目录
这是我的配置文件
'use strict';
var HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: __dirname + "/src/index.js",
output: {
path: __dirname + "/dist",
filename: "bundle.[hash:8].js",
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel'
},
{
test: /\.scss$/,
loaders: ["style-loader", "css-loader", "sass-loader"]
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: __dirname + "/src/index.html",
filename: __dirname + "/dist/index.html",
inject:true, //允许插件修改哪些内容,包括head与body
hash:false, //为静态资源生成hash值
minify:{ //压缩HTML文件
removeComments:true, //移除HTML中的注释
collapseWhitespace:false //删除空白符与换行符
}
})
],
devServer: {
contentBase: __dirname + "/dist",//本地服务器所加载的页面所在的目录
colors: true,//终端中输出结果为彩色
inline: true,//实时刷新
hot: true,
quiet: true
}
};
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
之前我也遇到过一样的问题,印象中是通过调整
output.publicPath参数来调整过来的:output.publicPath参数需要输入以'/'开头的绝对路径没看懂什么意思,你认为会访问哪个文件?
这个设置的第一个属性,是指定本地服务器访问的目录,其它目录访问不了