node.js - Webpack-dev-server 显示目录列表而不是应用程序页面

标签 node.js reactjs webpack-dev-server

我正在使用 React 构建渐进式 Web 应用程序,并且正在使用 Webpack 开发服务器。

enter image description here

我的网络应用程序配置:

var webpack = require('webpack');
var path = require('path');

module.exports = {
    entry: [
        'webpack-dev-server/client?http://127.0.0.1:8080',
        'webpack/hot/only-dev-server',
        './src/index.jsx'
    ],
    output: {
        path: path.join(__dirname,'public'),
        filename: 'bundle.js',
         publicPath: 'http://localhost:8080'
    },
    devServer: {
        contentBase: "./public",
        hot: true
    },
    resolve: {
        modulesDirectories: ['node_modules','src'],
        extensions: ['','.js']
    },
    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                exclude: /node_modules/,
                loaders: ['react-hot','babel?presets[]=react,presets[]=react,presets[]=es2015']
            }

        ]
    },
    plugins:[
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin()
    ]
};

这是我的目录结构:

enter image description here

请帮我解决这个问题,因为我看不到我的index.html。 我的配置文件有问题吗

最佳答案

您的index.html位于文件夹“src”中 所以你的 webpack.config.js 应该像这样:

devServer: {
    contentBase: "./src",
    hot: true
},

关于node.js - Webpack-dev-server 显示目录列表而不是应用程序页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38587376/

相关文章:

node.js - Node 的 Express,在集合上运行 Model 方法

javascript - 使用 Mongoose 通过嵌套文档属性查找

node.js - 有没有办法使用nodejs重新加载hasura远程模式

javascript - 使用 React 定期运行 fetch

reactjs - 如何使用外部IP访问webpack-dev-server

json - 如何使用 Webpack 将所有子目录中的 JSON 文件合二为一?

javascript - 使用 Socket.io 的 Express 4 路由

reactjs - 如何扩展 React 类型以支持 html 属性作为 Prop ?

javascript - react 不重新获取过期的缓存文件

Webpack 配置输出文件名使用方括号参数而不是纯文本