-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
updating Encore docs for 1.0 #14895
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
updating Encore docs for 1.0 #14895
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,31 +8,16 @@ While developing, instead of using ``yarn encore dev --watch``, you can use the | |
|
||
$ yarn encore dev-server | ||
|
||
This builds and serves the front-end assets from a new server. This server runs at | ||
``localhost:8080`` by default, meaning your build assets are available at ``localhost:8080/build``. | ||
This server does not actually write the files to disk; instead it servers them from memory, | ||
This builds and serves the front-end assets from a new server. This server runs at | ||
``localhost:8080`` by default, meaning your build assets are available at ``localhost:8080/build``. | ||
This server does not actually write the files to disk; instead it servers them from memory, | ||
allowing for hot module reloading. | ||
|
||
As a consequence, the ``link`` and ``script`` tags need to point to the new server. If you're using the | ||
``encore_entry_script_tags()`` and ``encore_entry_link_tags()`` Twig shortcuts (or are | ||
:ref:`processing your assets through entrypoints.json <load-manifest-files>` in some other way), | ||
As a consequence, the ``link`` and ``script`` tags need to point to the new server. If you're using the | ||
``encore_entry_script_tags()`` and ``encore_entry_link_tags()`` Twig shortcuts (or are | ||
:ref:`processing your assets through entrypoints.json <load-manifest-files>` in some other way), | ||
you're done: the paths in your templates will automatically point to the dev server. | ||
|
||
Enabling HTTPS using the Symfony Web Server | ||
------------------------------------------- | ||
|
||
If you're using the :doc:`Symfony web server </setup/symfony_server>` locally with HTTPS, | ||
you'll need to also tell the dev-server to use HTTPS. To do this, you can reuse the Symfony web | ||
server SSL certificate: | ||
|
||
.. code-block:: terminal | ||
|
||
# Unix-based systems | ||
$ yarn dev-server --https --pfx=$HOME/.symfony/certs/default.p12 | ||
|
||
# Windows | ||
$ encore dev-server --https --pfx=%UserProfile%\.symfony\certs\default.p12 | ||
|
||
dev-server Options | ||
------------------ | ||
|
||
|
@@ -66,53 +51,65 @@ method in your ``webpack.config.js`` file: | |
|
||
The ``Encore.configureDevServerOptions()`` method was introduced in Encore 0.28.4. | ||
|
||
Hot Module Replacement HMR | ||
-------------------------- | ||
Enabling HTTPS using the Symfony Web Server | ||
------------------------------------------- | ||
|
||
If you're using the :doc:`Symfony web server </setup/symfony_server>` locally with HTTPS, | ||
you'll need to also tell the dev-server to use HTTPS. To do this, you can reuse the Symfony web | ||
server SSL certificate: | ||
|
||
.. code-block:: javascript | ||
|
||
Encore *does* support `HMR`_ for :doc:`Vue.js </frontend/encore/vuejs>`, but | ||
does *not* work for styles anywhere at this time. To activate it, pass the ``--hot`` | ||
option: | ||
// webpack.config.js | ||
// ... | ||
const path = require('path'); | ||
|
||
Encore | ||
// ... | ||
|
||
.configureDevServerOptions(options => { | ||
options.https = { | ||
pfx: path.join(process.env.HOME, '.symfony/certs/default.p12'), | ||
} | ||
}) | ||
|
||
Then make sure you run the ``dev-server`` with the ``--https`` option: | ||
|
||
.. code-block:: terminal | ||
|
||
$ ./node_modules/.bin/encore dev-server --hot | ||
$ yarn encore dev-server --https | ||
|
||
If you want to use SSL with self-signed certificates, add the ``--https``, | ||
``--pfx=``, and ``--allowed-hosts`` options to the ``dev-server`` command in | ||
the ``package.json`` file: | ||
CORS Issues | ||
----------- | ||
|
||
.. code-block:: diff | ||
If you experience issues related to CORS (Cross Origin Resource Sharing), set | ||
the ``firewall`` option: | ||
|
||
{ | ||
... | ||
"scripts": { | ||
- "dev-server": "encore dev-server", | ||
+ "dev-server": "encore dev-server --https --pfx=$HOME/.symfony/certs/default.p12 --allowed-hosts=mydomain.wip", | ||
... | ||
} | ||
} | ||
.. code-block:: javascript | ||
|
||
If you experience issues related to CORS (Cross Origin Resource Sharing), add | ||
the ``--disable-host-check`` and ``--port`` options to the ``dev-server`` | ||
command in the ``package.json`` file: | ||
// webpack.config.js | ||
// ... | ||
|
||
Encore | ||
// ... | ||
|
||
.. code-block:: diff | ||
.configureDevServerOptions(options => { | ||
options.firewall = false; | ||
}) | ||
|
||
{ | ||
... | ||
"scripts": { | ||
- "dev-server": "encore dev-server", | ||
+ "dev-server": "encore dev-server --port 8080 --disable-host-check", | ||
... | ||
} | ||
} | ||
Hot Module Replacement HMR | ||
-------------------------- | ||
|
||
.. caution:: | ||
Hot module replacement is a superpower of the ``dev-server`` where styles and | ||
(in some cases) JavaScript can automatically update without needing to reload | ||
your page. HMR works automatically with CSS (as long as you're using the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh! Does it mean we don't have to use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't read about this specifically, but when I tested it on my project earlier (which DOES always use CSS extraction), it totally worked! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I confirm I didn't had to use |
||
``dev-server`` and Encore 1.0 or higher) but only works with some JavaScript | ||
(like :doc:`Vue.js </frontend/encore/vuejs>`). | ||
|
||
Beware that `it's not recommended to disable host checking`_ in general, but | ||
here it's required to solve the CORS issue. | ||
Comment on lines
-112
to
-113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that warning should be kept since it is still not recommended to disable those checks entirely (you can usually make it work by explicitly whitelisting hosts). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it here: #14929 |
||
.. versionadded:: 1.0.0 | ||
|
||
Before Encore 1.0, you needed to pass a ``--hot`` flag at the command line | ||
to enable HMR. You also needed to disable CSS extraction to enable HMR for | ||
CSS. That is no longer needed. | ||
|
||
.. _`webpack-dev-server`: https://webpack.js.org/configuration/dev-server/ | ||
.. _`HMR`: https://webpack.js.org/concepts/hot-module-replacement/ | ||
.. _`it's not recommended to disable host checking`: https://webpack.js.org/configuration/dev-server/#devserverdisablehostcheck |
This file was deleted.
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.
shall we redirect this?