我用的是Webpack-4。当前的行为是,当运行webpack-dev-server时,/build下的文件根本不会更新,它显示的是文件目录。
如果我删除/build下的文件,webpack-dev-server给出的文件不能获取/。我假设,它应该从内存中加载它们。
const HtmlWebPackPlugin = require("html-webpack-plugin");
const htmlPlugin = new HtmlWebPackPlugin({
template: "./src/index.html",
filename: "./index.html"
});
const path = require('path');
module.exports = {
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'build/'),
},
module: {
rules: [{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
presets: ["env","react"]
}
}
},
{
test: /\.html$/,
use: [{
loader: "html-loader",
options: {
minimize: true
}
}]
}
]
},
plugins: [
htmlPlugin
],
devServer: {
contentBase: "./build/",
port: 5555
}
}发布于 2018-08-06 01:00:32
下面是一些帮助我理解和调试本地webpack-dev-server配置的技巧:
http://localhost:{yourport}/webpack-dev-server。然后你可以点击其中一个文件(链接),它会向你显示提供服务的路径和文件的内容。webpack.config.js文件提供的内容。(有关您想要热重新加载的详细explanation)package.json
"scripts": {
"start": "webpack-dev-server --config webpack.config.js --hot --inline"
},webpack.config.js配置
...
output: {
filename: '[name].bundle.js',
path: path.join(__dirname, 'public', 'scripts'),
},
...
devServer: {
contentBase: path.join(__dirname, "public"),
publicPath: 'http://localhost:8080/scripts/',
port: 8080
},
...输出
i 「wds」: Project is running at http://localhost:8080/
i 「wds」: webpack output is served from http://localhost:8080/scripts/
i 「wds」: Content not from webpack is served from C:\Workspace\WebSite\public在输出的第2行,请注意,由于配置中的contentBase,http://localhost:8080/scripts/实际上指向磁盘上的C:\Workspace\WebSite\public\scripts。(这就是webpack也会放文件的地方:)!)
在publicPath配置中,尾部的反斜杠很重要。
https://stackoverflow.com/questions/49857724
复制相似问题