[英]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-boilerplate
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.