|
| 1 | +Using Encore in a Virtual Machine |
| 2 | +================================= |
| 3 | + |
| 4 | +Encore is compatible with virtual machines such as `VirtualBox`_ and `VMWare`_ |
| 5 | +but you may need to make some changes to your configuration to make it work. |
| 6 | + |
| 7 | +File Watching Issues |
| 8 | +-------------------- |
| 9 | + |
| 10 | +When using a virtual machine, your project root directory is shared with the |
| 11 | +virtual machine using `NFS`_. This introduces issues with files watching, so |
| 12 | +you must enable the `polling`_ option to make it work: |
| 13 | + |
| 14 | +.. code-block:: javascript |
| 15 | +
|
| 16 | + // webpack.config.js |
| 17 | +
|
| 18 | + // ... |
| 19 | +
|
| 20 | + // will be applied for `encore dev --watch` and `encore dev-server` commands |
| 21 | + Encore.configureWatchOptions(watchOptions => { |
| 22 | + watchOptions.poll = 250; // check for changes every 250 milliseconds |
| 23 | + }); |
| 24 | +
|
| 25 | +Development Server Issues |
| 26 | +------------------------- |
| 27 | + |
| 28 | +Configure the Public Path |
| 29 | +~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 30 | + |
| 31 | +.. note:: |
| 32 | + |
| 33 | + You can skip this section if your application is running on |
| 34 | + ``http://localhost`` instead a custom local domain-name like |
| 35 | + ``http://app.vm``. |
| 36 | + |
| 37 | +When running the development server, you will probably see the following errors |
| 38 | +in the web console: |
| 39 | + |
| 40 | +.. code-block:: text |
| 41 | +
|
| 42 | + GET http://localhost:8080/build/vendors~app.css net::ERR_CONNECTION_REFUSED |
| 43 | + GET http://localhost:8080/build/runtime.js net::ERR_CONNECTION_REFUSED |
| 44 | + ... |
| 45 | +
|
| 46 | +If your Symfony application is running on a custom domain (e.g. |
| 47 | +``http://app.vm``), you must configure the public path explicitly in your |
| 48 | +``package.json``: |
| 49 | + |
| 50 | +.. code-block:: diff |
| 51 | +
|
| 52 | + { |
| 53 | + ... |
| 54 | + "scripts": { |
| 55 | + - "dev-server": "encore dev-server", |
| 56 | + + "dev-server": "encore dev-server --public http://app.vm:8080", |
| 57 | + ... |
| 58 | + } |
| 59 | + } |
| 60 | +
|
| 61 | +After restarting Encore and reloading your web page, you will probably see |
| 62 | +different issues in the web console: |
| 63 | + |
| 64 | +.. code-block:: text |
| 65 | +
|
| 66 | + GET http://app.vm:8080/build/vendors~app.css net::ERR_CONNECTION_REFUSED |
| 67 | + GET http://app.vm:8080/build/runtime.js net::ERR_CONNECTION_REFUSED |
| 68 | +
|
| 69 | +You still need to make other configuration changes, as explained in the |
| 70 | +following sections. |
| 71 | + |
| 72 | +Allow External Access |
| 73 | +~~~~~~~~~~~~~~~~~~~~~ |
| 74 | + |
| 75 | +Add the ``--host 0.0.0.0`` argument to the ``dev-server`` configuration in your |
| 76 | +``package.json`` file to make the development server accept all incoming |
| 77 | +connections: |
| 78 | + |
| 79 | +.. code-block:: diff |
| 80 | +
|
| 81 | + { |
| 82 | + ... |
| 83 | + "scripts": { |
| 84 | + - "dev-server": "encore dev-server --public http://app.vm:8080", |
| 85 | + + "dev-server": "encore dev-server --public http://app.vm:8080 --host 0.0.0.0", |
| 86 | + ... |
| 87 | + } |
| 88 | + } |
| 89 | +
|
| 90 | +.. caution:: |
| 91 | + |
| 92 | + Make sure to run the development server inside your virtual machine only; |
| 93 | + otherwise other computers can have access to it. |
| 94 | + |
| 95 | +Fix "Invalid Host header" Issue |
| 96 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 97 | + |
| 98 | +Webpack will respond ``Invalid Host header`` when trying to access files from |
| 99 | +the dev-server. To fix this, add the argument ``--disable-host-check``: |
| 100 | + |
| 101 | +.. code-block:: diff |
| 102 | +
|
| 103 | + { |
| 104 | + ... |
| 105 | + "scripts": { |
| 106 | + - "dev-server": "encore dev-server --public http://app.vm:8080 --host 0.0.0.0", |
| 107 | + + "dev-server": "encore dev-server --public http://app.vm:8080 --host 0.0.0.0 --disable-host-check", |
| 108 | + ... |
| 109 | + } |
| 110 | + } |
| 111 | +
|
| 112 | +.. caution:: |
| 113 | + |
| 114 | + Beware that `it's not recommended to disable host checking`_ in general, but |
| 115 | + here it's required to solve the issue when using Encore in a virtual machine. |
| 116 | + |
| 117 | +.. _`VirtualBox`: https://www.virtualbox.org/ |
| 118 | +.. _`VMWare`: https://www.vmware.com |
| 119 | +.. _`NFS`: https://en.wikipedia.org/wiki/Network_File_System |
| 120 | +.. _`polling`: https://webpack.js.org/configuration/watch/#watchoptionspoll |
| 121 | +.. _`it's not recommended to disable host checking`: https://webpack.js.org/configuration/dev-server/#devserverdisablehostcheck |
0 commit comments