简体   繁体   English

从本地网络访问Webpack Dev Server? (在移动设备上实现热重新加载)

[英]Accessing Webpack Dev Server from local network? (React Hot Reloading on mobile)

I want to test a React website from a device on my local network. 我想从本地网络上的设备测试React网站。 It works on other PCs but not on my phone. 它适用于其他PC,但不适用于我的手机。

Do you guys have any ideas what might cause this? 你们有什么想法会导致这个吗? Here's how my config file looks: 这是我的配置文件的外观:

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

module.exports = {

    entry: {
        mainFeedPage: [
            'webpack/hot/only-dev-server',
            './src/mainFeedPage.js'
        ],
        venues: [
            'webpack/hot/only-dev-server',
            './src/venues.js'
        ],  
        artists: [
            'webpack/hot/only-dev-server',
            './src/artists.js'
        ]  
    },
    output: {
        path: path.resolve(__dirname, 'public'),
        filename: 'js/[name].js',
        publicPath: '/public/'
    },
    devServer: {
        inline:true,
        port: 4000,
        hot: true,
        colors: true,
        progress: true,
        host: '0.0.0.0'

    },
    module: {
        loaders: [
            {
                test: /\.jsx?$/,
                exclude: /node_modules/,
                loaders: [
                    'react-hot', 
                    'babel?presets[]=react,presets[]=es2015'
                ] 
            }
        ]
    },

    plugins: [
        new webpack.HotModuleReplacementPlugin(),
        new webpack.NoErrorsPlugin(),
        new webpack.optimize.CommonsChunkPlugin({

            // Export bundles for each entry and one for code they share
            name: "shared",
            filename: "js/shared.js",
            chunks: ["mainFeedPage", "venues"]
        })
    ],

    resolve: {
        modulesDirectories: ['node_modules', 'src', 'components', 'stores'],
        extensions: ['', '.js', '.scss'],
        root: [path.join(__dirname, './src')],
    }
};

UPDATE Tried this, but couldn't get it to work: https://github.com/gaearon/react-hot-loader/issues/107#issuecomment-85712166 更新试过这个,但无法让它工作: https//github.com/gaearon/react-hot-loader/issues/107#issuecomment-85712166

This is not a direct fix, but I've got a project based off of the React Transform boilerplate offered by Dan Abramov and it works flawlessly on mobile Android devices. 这不是一个直接的解决方案,但我有一个基于Dan Abramov提供的React Transform样板的项目,它可以在移动Android设备上完美运行。 Haven't tested on iOS. 尚未在iOS上测试过。 It's very similar in principle to React Hot Loader: https://github.com/gaearon/react-transform-boilerplate 它在原理上与React Hot Loader非常相似: https//github.com/gaearon/react-transform-b​​oilerplate

It's deprecated, but so is React Hot Loader until version 3 is released. 它已被弃用,但在版本3发布之前,React Hot Loader也是如此。

Admittedly, this 'solution' is probably like hitting a nail with a sledgehammer. 不可否认,这种“解决方案”可能就像是用大锤敲打钉子。 Hopefully someone can offer something simpler that doesn't require swapping a bunch of dependencies and build configurations. 希望有人可以提供更简单的东西,不需要交换一堆依赖项和构建配置。

Christian's example solved my issue. 克里斯蒂安的榜样解决了我的问题。 You'd have to customize the webpack.config files if you want to use bundles. 如果要使用捆绑包,则必须自定义webpack.config文件。 This could have been solved just by googling, but it took me a lot of time to understand how Node and Express work... 这可以通过谷歌搜索解决,但我花了很多时间来了解Node和Express如何工作......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React&Webpack Dev Server:热重装不起作用 - React & Webpack Dev Server: Hot Reloading not working webpack-dev-server 不热重载(webpack 5) - webpack-dev-server not hot reloading (webpack 5) Webpack Dev Server不热重载.vue文件 - Webpack Dev Server Not Hot Reloading .vue files Webpack 3 webpack-dev-server热重装不起作用 - Webpack 3 webpack-dev-server hot reloading does not work 使用热重载的ReactJS服务器端渲染(webpack-dev-server) - ReactJS server side rendering with hot reloading (webpack-dev-server) webpack-dev-server和webpack->将文件输出到父目录,并使webpack-dev-server热重装仍然有效 - webpack-dev-server and webpack -> output file to parent directory and have webpack-dev-server hot reloading still working 尽管我已经完成了“内联:真”,但 Webpack 开发服务器热重载无法与 reactjs 一起使用? - Webpack dev server hot reloading not working with reactjs, though i have done "inline:true"? webpack-dev-server with hot reload重新加载整个页面并进行css更改 - webpack-dev-server with hot reload reloading entire page with css changes 如何从 local.network 中的设备访问 webpack-dev-server? - How to get access to webpack-dev-server from devices in local network? 使用webpack-dev实现Hot loader 3 - React Hot loader 3 with webpack-dev
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM