Skip to content

Instantly share code, notes, and snippets.

@owenstrevor
Last active February 27, 2019 16:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save owenstrevor/4a16f9329ad0bbb953b685054ca135cf to your computer and use it in GitHub Desktop.
Save owenstrevor/4a16f9329ad0bbb953b685054ca135cf to your computer and use it in GitHub Desktop.
Phoenix Webpack.config.js Auto-Reload (Phoenix 1.4.1)
# the below starts on line 9 of dev.exs, the rest of the file remains unchanged
# Just npm install nodemon globally with the below command, no need to add it to package.json
# $ npm install --global nodemon
# lines 13 to 16 below are what I added to get this to work
# lines 17 to 23 are already there with a new install (do not delete them, just add nodemon stuff before it)
config :my_app, MyAppWeb.Endpoint,
http: [port: 4000],
debug_errors: true,
code_reloader: true,
check_origin: false,
watchers: [
nodemon: [
"--watch",
"webpack.config.js",
"--exec",
"node_modules/webpack/bin/webpack.js",
"--mode",
"development",
"--watch-stdin",
cd: Path.expand("../assets", __DIR__)
]
]
@owenstrevor
Copy link
Author

This is what the top of dev.exs looks like in a new install

config :my_app, MyAppWeb.Endpoint,
  http: [port: 4000],
  debug_errors: true,
  code_reloader: true,
  check_origin: false,
  watchers: [
    node: [
      "node_modules/webpack/bin/webpack.js",
      "--mode",
      "development",
      "--watch-stdin",
      cd: Path.expand("../assets", __DIR__)
    ]
  ]

This is what you need to change it to for Webpack to auto-reload with the new settings after you modify config files

config :my_app, MyAppWeb.Endpoint,
  http: [port: 4000],
  debug_errors: true,
  code_reloader: true,
  check_origin: false,
  watchers: [
    nodemon: [
      "--watch",
      "webpack.config.js",
      "--exec",
      "node_modules/webpack/bin/webpack.js",
      "--mode",
      "development",
      "--watch-stdin",
      cd: Path.expand("../assets", __DIR__)
    ]
  ]

Just install nodemon globally and you are good to go (Phoenix 1.4.1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment