找不到Webpack-dev-server子页面

时间:2016-09-24 00:53:02

标签: javascript reactjs webpack webpack-dev-server file-not-found

我正在使用webpack做出反应。我的应用程序在使用webpack-dev-server之前运行良好。现在只有主页工作,其他人返回“404 not found”。也许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是造成这个问题的人。

谢谢!

2 个答案:

答案 0 :(得分:2)

我找到了答案。对于有相同问题的人,我们需要将“historyApiFallback:true”添加到devServerConfig:

devServer: {
    noInfo: true,
    hot: true,
    inline: true,
    historyApiFallback: true
},

答案 1 :(得分:0)

你可以改变你的npm脚本吗

"start": "webpack --watch & webpack-dev-server --content-base public"

"start": "webpack --watch & webpack-dev-server --content-base public/"

看看会发生什么?否则我会回来帮助你。