找不到 Webpack-dev-server 子页面
Webpack-dev-server sub pages not found
我正在使用与 webpack 的反应。在使用 webpack-dev-server 之前,我的应用程序运行良好。现在只有主页可用,其他 return“404 未找到”。也许 webpack.config.js 有问题?
var webpack = require("webpack");
var path = require("path");
var BUILD_DIR = path.resolve(__dirname, "public");
var APP_DIR = path.resolve(__dirname, "app");
var config = {
entry: [
"webpack/hot/only-dev-server",
APP_DIR + "/main.js",
"webpack-dev-server/client?localhost:8080"
],
output: {
path: BUILD_DIR + "/dist",
filename: "bundle.js",
},
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
}),
new webpack.HotModuleReplacementPlugin()
],
module: {
loaders: [...],
},
devServer: {
noInfo: true,
hot: true,
inline: true
},
}
module.exports = config;
还有我在 package.json 中的脚本:
"start": "webpack --watch & webpack-dev-server --content-base public"
Webpack 生成良好的捆绑文件。所以我认为是 webpack-dev-server 导致了这个问题。
谢谢!
你能改变你的 npm 脚本吗
"start": "webpack --watch & webpack-dev-server --content-base public"
到
"start": "webpack --watch & webpack-dev-server --content-base public/"
看看会发生什么?不然我回来帮你
我找到了答案。对于遇到同样问题的人,我们需要在devServerConfig中添加"historyApiFallback: true":
devServer: {
noInfo: true,
hot: true,
inline: true,
historyApiFallback: true
},
我正在使用与 webpack 的反应。在使用 webpack-dev-server 之前,我的应用程序运行良好。现在只有主页可用,其他 return“404 未找到”。也许 webpack.config.js 有问题?
var webpack = require("webpack");
var path = require("path");
var BUILD_DIR = path.resolve(__dirname, "public");
var APP_DIR = path.resolve(__dirname, "app");
var config = {
entry: [
"webpack/hot/only-dev-server",
APP_DIR + "/main.js",
"webpack-dev-server/client?localhost:8080"
],
output: {
path: BUILD_DIR + "/dist",
filename: "bundle.js",
},
plugins: [
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery"
}),
new webpack.HotModuleReplacementPlugin()
],
module: {
loaders: [...],
},
devServer: {
noInfo: true,
hot: true,
inline: true
},
}
module.exports = config;
还有我在 package.json 中的脚本:
"start": "webpack --watch & webpack-dev-server --content-base public"
Webpack 生成良好的捆绑文件。所以我认为是 webpack-dev-server 导致了这个问题。
谢谢!
你能改变你的 npm 脚本吗
"start": "webpack --watch & webpack-dev-server --content-base public"
到
"start": "webpack --watch & webpack-dev-server --content-base public/"
看看会发生什么?不然我回来帮你
我找到了答案。对于遇到同样问题的人,我们需要在devServerConfig中添加"historyApiFallback: true":
devServer: {
noInfo: true,
hot: true,
inline: true,
historyApiFallback: true
},