Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get rid of ^H when using webpack with iex -S mix phoenix.server?

I use webpack with phoenix. Many ^H will be output when I use iex -S mix phoenix.server to start the server. Like this

iex(1)> ^H^H^H^H^H^H^H^H^H^H^H^H  0% compile
^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H 10% 
0/1 build modules^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H 70% 
1/1 build modules^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H 40% 
1/2 build modules^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H^H 30% 
1/3 build modules[bootstrap-sass-loader]: styleLoader: style-loader!
css-loader!sass-loader
...

What's the problem? And how to solve it?

like image 944
Tony Han Avatar asked Oct 25 '15 17:10

Tony Han


2 Answers

It's because I use --progress in the my phoenix watchers config:

watchers: [node: ["node_modules/webpack/bin/webpack.js", "--watch", "--colors",
  "--progress"]]

Then webpack will output \b to make a progress as the code shows https://github.com/webpack/webpack/blob/master/bin/convert-argv.js#L408.

Finally, my solution is changing the webpack arguments to support both mix phoenix and iex -S mix phoenix.server:

webpack_args = ["node_modules/webpack/bin/webpack.js", "--watch", "--colors",
  "--progress"]
# Remove progress argument to make iex display log normally
if IEx.started?, do: webpack_args = List.delete(webpack_args, "--progress")

config :sample, Sample.Endpoint,
  # ...
  watchers: [node: webpack_args]
like image 164
Tony Han Avatar answered Sep 28 '22 18:09

Tony Han


The cause of this output is the webpack --progress flag, as @tony-han points out correctly, which is configured as a watcher and started for the Phoenix endpoint in dev environment.

This and other watchers are run only, if the option :server is activated. At least in recent Phoenix versions this setting is set to false by default, and it's only activated by the mix phx.server task. That means by default this shouldn't happen in iex at all.

You can check your dev environment's endpoint configuration for a setting server: true, which is unnecessary. If you remove it, this problem should be resolved.

NB, the server: true setting (or alternatively the more global config :phoenix, :serve_endpoints, true) should given in prod environment, as this is often started by running a release.

like image 40
febeling Avatar answered Sep 28 '22 19:09

febeling