-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Encore: add guide to use Encore in a virtual machine #11422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
Using Encore in a Virtual Machine | ||
================================= | ||
|
||
You may encounter some issues when using Encore in a virtual machine, like VirtualBox or VMWare. | ||
|
||
Fix watching issues | ||
------------------- | ||
|
||
When using a virtual machine, your project root directory is shared with the virtual machine with `NFS`_. | ||
This is really useful, but it introduces some issues with files watching. | ||
|
||
You must enable `polling`_ option to make it work: | ||
|
||
.. code-block:: javascript | ||
|
||
// webpack.config.js | ||
|
||
// ... | ||
|
||
// will be applied for `encore dev --watch` and `encore dev-server` commands | ||
Encore.configureWatchOptions(watchOptions => { | ||
watchOptions.poll = 250; // check for changes every 250 ms | ||
}); | ||
|
||
Fix development server | ||
---------------------- | ||
|
||
Configure public path | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
.. note:: | ||
|
||
You can skip this sub-section if your app is running on ``http://localhost`` | ||
and not a custom local domain-name like ``http://app.vm``. | ||
|
||
When running the development server, you will probably face the following errors in the web console: | ||
|
||
.. code-block:: text | ||
|
||
GET http://localhost:8080/build/vendors~app.css net::ERR_CONNECTION_REFUSED | ||
GET http://localhost:8080/build/runtime.js net::ERR_CONNECTION_REFUSED | ||
... | ||
|
||
If your Symfony application is running on ``http://app.vm``, you must configure the public path explicitly | ||
in your ``package.json``: | ||
|
||
.. code-block:: diff | ||
|
||
{ | ||
... | ||
"scripts": { | ||
- "dev-server": "encore dev-server", | ||
+ "dev-server": "encore dev-server --public http://app.vm:8080", | ||
... | ||
} | ||
} | ||
|
||
Kocal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
After restarting Encore and reloading your web page, you will probably face different issues: | ||
|
||
.. code-block:: text | ||
|
||
GET http://app.vm:8080/build/vendors~app.css net::ERR_CONNECTION_REFUSED | ||
GET http://app.vm:8080/build/runtime.js net::ERR_CONNECTION_REFUSED | ||
|
||
Encore understood our modification but it's still not working. There is still two things to do. | ||
|
||
Allow external access | ||
~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
You must configure how you run the `webpack-dev-server`_. | ||
This can easily be done in your ``package.json`` by adding ``--host 0.0.0.0`` argument: | ||
|
||
Kocal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.. code-block:: diff | ||
|
||
{ | ||
... | ||
"scripts": { | ||
- "dev-server": "encore dev-server --public http://app.vm:8080", | ||
+ "dev-server": "encore dev-server --public http://app.vm:8080 --host 0.0.0.0", | ||
... | ||
} | ||
} | ||
|
||
.. warning:: | ||
|
||
Using ``--host 0.0.0.0`` makes your development server accept all incoming connections. | ||
Be sure to run the development server inside your virtual machine and not outside, otherwise other computers can have access to it. | ||
|
||
Fix "Invalid Host header" issue | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Webpack will respond ``Invalid Host header`` when trying to access files from the dev-server. | ||
To fix this, add the argument ``--disable-host-check``: | ||
|
||
.. code-block:: diff | ||
|
||
{ | ||
... | ||
"scripts": { | ||
- "dev-server": "encore dev-server --public http://app.vm:8080 --host 0.0.0.0", | ||
+ "dev-server": "encore dev-server --public http://app.vm:8080 --host 0.0.0.0 --disable-host-check", | ||
... | ||
} | ||
} | ||
|
||
Kocal marked this conversation as resolved.
Show resolved
Hide resolved
|
||
.. warning:: | ||
|
||
This is usually not recommended to disable host checking, `more information here <https://webpack.js.org/configuration/dev-server/#devserverdisablehostcheck>`_. | ||
|
||
.. _`NFS`: https://en.wikipedia.org/wiki/Network_File_System | ||
.. _`polling`: https://webpack.js.org/configuration/watch/#watchoptionspoll | ||
.. _`webpack-dev-server`: https://webpack.js.org/configuration/dev-server/ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe also add a note here about the CLI equivalent (
--watch-poll
)?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep why not, but it means that the user will have to pass
--watch-poll
two times in itspackage.json
😕