I have been doing this for about a week, and I have not been able to get them to work together. I will be eternally grateful if anyone can help me, I spent so much time.
Problem:
If I proxy myserver.dev hot reboot 404s. Changing publicPath does nothing. I attach the url to webpack-hot-middleware / client, it fixes the path, but the "GET" error appears in the hmr file in the console without information. A hot reload works fine if I keep it in HTML and ignore any php / MAMP. I am generally very confused, and I probably missed a simple concept.
What I'm trying to work together:
- Wordpress for its REST API
- Respond to species and ui
- MAMP for localhost and MySQL
- BrowserSync for testing on different devices
- Webpack for compilation and hot restart
This is the template I used: https://github.com/Browsersync/recipes/tree/master/recipes/webpack.react-hot-loader
Style Catalog Structure:
- / on
- / center
-/Components
- / containers
- / styles
--app.js
-bundle.js
-functions.php
-index.php
-package.json
-server.js
-style.css
-webpack.config.js
I tried a million configurations, so I touched the code below for simplicity.
webpack.config.js:
var webpack = require('webpack'); var path = require('path'); module.exports = { context: path.join(__dirname, 'src'), entry: [ 'webpack/hot/dev-server', 'webpack-hot-middleware/client', './app' ], output: { path: __dirname, publicPath: __dirname, filename: 'bundle.js' }, plugins: [ new webpack.optimize.OccurenceOrderPlugin(), new webpack.HotModuleReplacementPlugin(), new webpack.NoErrorsPlugin() ], module: { loaders: [ { test: /\.jsx?$/, exclude: /node_modules/, loaders: ['react-hot', 'babel'] } ] } };
server.js:
var browserSync = require('browser-sync'); var webpack = require('webpack'); var webpackDevMiddleware = require('webpack-dev-middleware'); var webpackHotMiddleware = require('webpack-hot-middleware'); var webpackConfig = require('./webpack.config'); var bundler = webpack(webpackConfig); browserSync({ proxy: { target: 'http://myserver.dev', middleware: [ webpackDevMiddleware(bundler, {
package.json:
{ "main": "server.js", "scripts": { "build": "webpack", "start": "node ." }, "dependencies": { "babel-core": "^5.8.9", "babel-loader": "^5.3.2", "browser-sync": "^2.8.0", "react": "^0.13.3", "react-hot-loader": "^1.2.8", "webpack": "^1.10.5", "webpack-dev-middleware": "^1.2.0", "webpack-hot-middleware": "^1.1.0" } }