简体   繁体   中英

Webpack dev server showing ~ / in browser

I have setup a webpack dev server for my application (with hot loading for React), but when I visit http://localhost:8080 all I see is

~ /

on the screen. When i run npm start, the build says it compiled successfully. I am building this via Bash on Windows 10. Below is my webpack.config.js file:

// hack for Ubuntu on Windows
try {
    require('os').networkInterfaces();
}
catch (e) {
    require('os').networkInterfaces = () => ({});
}

const path = require('path');
const webpack = require("webpack");

module.exports = {
    devServer: {
        hot: true,
        contentBase: path.resolve(__dirname, 'dist'),
        publicPath: '/'
    },
    devtool: 'inline-source-map',
    entry: [
        'react-hot-loader/patch',
        'webpack-dev-server/client?http://localhost:8080',
        'webpack/hot/only-dev-server',
        './src/app/index.js'
    ],
    module: {
        rules: [{
            test: /\.js?$/,
            use: ['babel-loader'],
            exclude: /node_modules/
        },{
            test: /\.jsx?$/,
            use: ['babel-loader?' + JSON.stringify({
                presets: ["es2015", "stage-2", "react"]
            })],
            exclude: /node_modules/
        },{
            test: /\.css?$/,
            use: ['style-loader','css-loader?modules']
        },{
            test: /\.jpg?$/,
            use: ['file-loader']
        },{
            test: /\.ico$/,
            use: ["file-loader"]
        },{
            test: /\.png$/,
            use: ["url-loader?limit=100000"]
        },{
            test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
            use: ["url-loader?limit=10000&mimetype=application/font-woff"]
        },{
            test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
            use: ["url-loader"]
        },{
            test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
            use: ["file-loader"]
        },{
            test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
            use: ["url-loader?limit=10000&mimetype=image/svg+xml"]
        }]
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        publicPath: '/',
        filename: 'bundle.js'
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env': {
                'NODE_ENV': JSON.stringify('dev')
            }
        }),
        new webpack.HotModuleReplacementPlugin(),
        // enable HMR globally

        new webpack.NamedModulesPlugin()
        // prints more readable module names in the browser console on HMR updates
    ],
    resolve: {
        extensions: ['.js', '.jsx', '.css']
    }
};

发现我没有将index.html文件放置在dist文件夹中(从中进行捆绑的服务器)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM