2016-12-01 39 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

我知道感覺:)如果你還記得或有一些代碼示例,請發佈它。在整個互聯網上似乎沒有解決方案:) –

相關問題