2016-12-01 40 views
1

我正在运行PHP应用localhost:8000
我想使用webpack-dev-server来重新加载cssreactjs组件。
已经设置了代理http://localhost:8000webpack-dev-server未重新加载浏览器。Webpack dev服务器实时刷新代理

这里的webpack.config.js

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

module.exports = { 
    entry: [ 
     './src/app.js' 
    ], 
    output: { 
     path: path.join(__dirname, 'dist'), 
     publicPath: 'http://localhost:8000', 
     filename: 'app.js' 
    }, 
    module: { 
     loaders: [ 
      { 
       test: /\.js$/, 
       exclude: /node_modules/, 
       loaders: [ 'react-hot', 'babel-loader' ] 
      }, 
      { 
       test: /\.scss$/, 
       loaders: [ 'style-loader', 'css-loader', 'sass-loader' ] 
      } 
     ] 
    }, 
    postcss: [ 
     autoprefixer(
      { 
       browsers: [ 
        'last 2 versions' 
       ] 
      } 
     ) 
    ], 
    devServer: { 
     port: 3000, 
     proxy: { 
      '**': { 
       target: 'http://localhost:8000', 
       secure: false, 
       changeOrigin: true 
      } 
     } 
    } 
} 

我访问webpack-dev-serverhttp://localhost:3000/webpack-dev-server/

更改我的react组件确实会导致webpack-dev-server重新编译,但浏览器不会更新。

正在运行webpack编译dist/app.js文件,因为手动调用它并重新加载浏览器。

回答

-1

所以我的publicPath是错的。
这里的修复:

output: { 
    path: path.join(__dirname, 'dist'), 
    publicPath: 'http://localhost:3000/dist/', 
    filename: 'app.js' 
}, 

更新:但它似乎是重新加载浏览器_(ツ)_ /¯

+0

你每设法解决这个问题?我也在尝试代理,并且在更改之后,整个浏览器都会刷新,而不是在没有刷新的情况下注入更改。我正在使用webpack-dev-server,并在客户端和服务器端的节点服务器上进行反应 - 热重新加载。 –

+0

我想我是。但它已经有一段时间了。不记得我做了什么:) – resting

+0

我知道感觉:)如果你还记得或有一些代码示例,请发布它。在整个互联网上似乎没有解决方案:) –

相关问题