@@ -8,31 +8,16 @@ While developing, instead of using ``yarn encore dev --watch``, you can use the
88
99 $ yarn encore dev-server
1010
11- This builds and serves the front-end assets from a new server. This server runs at
12- ``localhost:8080 `` by default, meaning your build assets are available at ``localhost:8080/build ``.
13- This server does not actually write the files to disk; instead it servers them from memory,
11+ This builds and serves the front-end assets from a new server. This server runs at
12+ ``localhost:8080 `` by default, meaning your build assets are available at ``localhost:8080/build ``.
13+ This server does not actually write the files to disk; instead it servers them from memory,
1414allowing for hot module reloading.
1515
16- As a consequence, the ``link `` and ``script `` tags need to point to the new server. If you're using the
17- ``encore_entry_script_tags() `` and ``encore_entry_link_tags() `` Twig shortcuts (or are
18- :ref: `processing your assets through entrypoints.json <load-manifest-files >` in some other way),
16+ As a consequence, the ``link `` and ``script `` tags need to point to the new server. If you're using the
17+ ``encore_entry_script_tags() `` and ``encore_entry_link_tags() `` Twig shortcuts (or are
18+ :ref: `processing your assets through entrypoints.json <load-manifest-files >` in some other way),
1919you're done: the paths in your templates will automatically point to the dev server.
2020
21- Enabling HTTPS using the Symfony Web Server
22- -------------------------------------------
23-
24- If you're using the :doc: `Symfony web server </setup/symfony_server >` locally with HTTPS,
25- you'll need to also tell the dev-server to use HTTPS. To do this, you can reuse the Symfony web
26- server SSL certificate:
27-
28- .. code-block :: terminal
29-
30- # Unix-based systems
31- $ yarn dev-server --https --pfx=$HOME/.symfony/certs/default.p12
32-
33- # Windows
34- $ encore dev-server --https --pfx=%UserProfile%\.symfony\certs\default.p12
35-
3621dev-server Options
3722------------------
3823
@@ -66,53 +51,65 @@ method in your ``webpack.config.js`` file:
6651
6752 The ``Encore.configureDevServerOptions() `` method was introduced in Encore 0.28.4.
6853
69- Hot Module Replacement HMR
70- --------------------------
54+ Enabling HTTPS using the Symfony Web Server
55+ -------------------------------------------
56+
57+ If you're using the :doc: `Symfony web server </setup/symfony_server >` locally with HTTPS,
58+ you'll need to also tell the dev-server to use HTTPS. To do this, you can reuse the Symfony web
59+ server SSL certificate:
60+
61+ .. code-block :: javascript
7162
72- Encore *does * support `HMR `_ for :doc: `Vue.js </frontend/encore/vuejs >`, but
73- does *not * work for styles anywhere at this time. To activate it, pass the ``--hot ``
74- option:
63+ // webpack.config.js
64+ // ...
65+ const path = require (' path' );
66+
67+ Encore
68+ // ...
69+
70+ .configureDevServerOptions (options => {
71+ options .https = {
72+ pfx: path .join (process .env .HOME , ' .symfony/certs/default.p12' ),
73+ }
74+ })
75+
76+ Then make sure you run the ``dev-server `` with the ``--https `` option:
7577
7678.. code-block :: terminal
7779
78- $ ./node_modules/.bin/ encore dev-server --hot
80+ $ yarn encore dev-server --https
7981
80- If you want to use SSL with self-signed certificates, add the ``--https ``,
81- ``--pfx= ``, and ``--allowed-hosts `` options to the ``dev-server `` command in
82- the ``package.json `` file:
82+ CORS Issues
83+ -----------
8384
84- .. code-block :: diff
85+ If you experience issues related to CORS (Cross Origin Resource Sharing), set
86+ the ``firewall `` option:
8587
86- {
87- ...
88- "scripts": {
89- - "dev-server": "encore dev-server",
90- + "dev-server": "encore dev-server --https --pfx=$HOME/.symfony/certs/default.p12 --allowed-hosts=mydomain.wip",
91- ...
92- }
93- }
88+ .. code-block :: javascript
9489
95- If you experience issues related to CORS (Cross Origin Resource Sharing), add
96- the ``--disable-host-check `` and ``--port `` options to the ``dev-server ``
97- command in the ``package.json `` file:
90+ // webpack.config.js
91+ // ...
92+
93+ Encore
94+ // ...
9895
99- .. code-block :: diff
96+ .configureDevServerOptions (options => {
97+ options .firewall = false ;
98+ })
10099
101- {
102- ...
103- "scripts": {
104- - "dev-server": "encore dev-server",
105- + "dev-server": "encore dev-server --port 8080 --disable-host-check",
106- ...
107- }
108- }
100+ Hot Module Replacement HMR
101+ --------------------------
109102
110- .. caution ::
103+ Hot module replacement is a superpower of the ``dev-server `` where styles and
104+ (in some cases) JavaScript can automatically update without needing to reload
105+ your page. HMR works automatically with CSS (as long as you're using the
106+ ``dev-server `` and Encore 1.0 or higher) but only works with some JavaScript
107+ (like :doc: `Vue.js </frontend/encore/vuejs >`).
111108
112- Beware that `it's not recommended to disable host checking `_ in general, but
113- here it's required to solve the CORS issue.
109+ .. versionadded :: 1.0.0
114110
111+ Before Encore 1.0, you needed to pass a ``--hot `` flag at the command line
112+ to enable HMR. You also needed to disable CSS extraction to enable HMR for
113+ CSS. That is no longer needed.
115114
116115.. _`webpack-dev-server` : https://webpack.js.org/configuration/dev-server/
117- .. _`HMR` : https://webpack.js.org/concepts/hot-module-replacement/
118- .. _`it's not recommended to disable host checking` : https://webpack.js.org/configuration/dev-server/#devserverdisablehostcheck
0 commit comments