Skip to content
Advertisement

How to set up live reloading with webpack-encore in a Symfony project?

I have created a Symfony full web app with the given command symfony new app --webapp. It came with Webpack configured with webpack-encore. I can have my assets compiled with npm run watch. But the browser don’t reload automatically when my I make changes. I have tried webpack-dev-server following Symfony’s official documentation here, but didn’t work.

webpack.config.js (I just removed the comments):

JavaScript

package.json:

JavaScript

Advertisement

Answer

You can set up live reloading with webpack-encore in a Symfony project with the help of Browsersync. Follow carefully the below steps and you will be good to go.

  1. Step one:
JavaScript
  1. Edit webpack.config.js (there are comments for the lines to add):
JavaScript
  1. Add the line below inside your .env (the url should be the one you get when you make symfony serve):
JavaScript
  1. Open a terminal in your project folder and type:
JavaScript
  1. Open a second terminal in your project folder and type:
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement