问题
I'm running a PHP app at localhost:8000.
I want to use webpack-dev-server to hot reload css, react and js components.
Had set a proxy to http://localhost:8000 but webpack-dev-server isn't reloading the browser.
Here's the 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
}
}
}
}
I'm accessing the webpack-dev-server at http://localhost:3000/webpack-dev-server/.
Changing my react component does cause webpack-dev-server to recompile, but the browser doesn't update.
Running webpack does compile the dist/app.js file, as calling it manually and reloading the browser works.
回答1:
So my publicPath was wrong.
Here's the fix:
output: {
path: path.join( __dirname, 'dist' ),
publicPath: 'http://localhost:3000/dist/',
filename: 'app.js'
},
update: But it seems to be reloading the browser ¯_(ツ)_/¯
来源:https://stackoverflow.com/questions/40903038/webpack-dev-server-live-reload-with-proxy