Skip to content
This repository was archived by the owner on Oct 8, 2021. It is now read-only.

Commit a85f968

Browse files
committed
updating Encore docs for 1.0
1 parent d7899c3 commit a85f968

12 files changed

+92
-186
lines changed

Diff for: .doctor-rst.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ whitelist:
8888
- '.. versionadded:: 1.3' # MakerBundle
8989
- '.. versionadded:: 1.8' # MakerBundle
9090
- '.. versionadded:: 1.6' # Flex in setup/upgrade_minor.rst
91+
- '.. versionadded:: 1.0.0' # Encore
9192
- '0 => 123' # assertion for var_dumper - components/var_dumper.rst
9293
- '1 => "foo"' # assertion for var_dumper - components/var_dumper.rst
9394
- '123,' # assertion for var_dumper - components/var_dumper.rst

Diff for: _build/redirection_map

+1
Original file line numberDiff line numberDiff line change
@@ -511,3 +511,4 @@
511511
/messenger/message-recorder messenger/dispatch_after_current_bus
512512
/components/stopwatch https://github.com/symfony/stopwatch
513513
/service_container/3.3-di-changes https://symfony.com/doc/3.4/service_container/3.3-di-changes.html
514+
/frontend/encore/shared-entry /frontend/encore/split-chunks

Diff for: frontend.rst

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ Optimizing
6161
* :doc:`Using a CDN </frontend/encore/cdn>`
6262
* :doc:`/frontend/encore/code-splitting`
6363
* :doc:`/frontend/encore/split-chunks`
64-
* :doc:`Creating a "Shared" entry for re-used modules </frontend/encore/shared-entry>`
6564
* :doc:`/frontend/encore/url-loader`
6665

6766
Guides

Diff for: frontend/encore/advanced-config.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ To do that, modify the config after fetching it from Encore:
1212
1313
// webpack.config.js
1414
15-
var Encore = require('@symfony/webpack-encore');
15+
const Encore = require('@symfony/webpack-encore');
1616
1717
// ... all Encore config here
1818
1919
// fetch the config, then modify it!
20-
var config = Encore.getWebpackConfig();
20+
const config = Encore.getWebpackConfig();
2121
2222
// add an extension
2323
config.resolve.extensions.push('json');
@@ -208,8 +208,8 @@ The following code is equivalent:
208208
The following loaders are configurable with ``configureLoaderRule()``:
209209
- ``javascript`` (alias ``js``)
210210
- ``css``
211-
- ``images``
212-
- ``fonts``
211+
- ``images`` (but use ``configureImageRule()`` instead)
212+
- ``fonts`` (but use ``configureFontRule()`` instead)
213213
- ``sass`` (alias ``scss``)
214214
- ``less``
215215
- ``stylus``

Diff for: frontend/encore/copy-files.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ To reference an image tag from inside a JavaScript file, *require* the file:
1616
1717
// returns the final, public path to this file
1818
// path is relative to this file - e.g. assets/images/logo.png
19-
const logoPath = require('../images/logo.png');
19+
import logoPath from '../images/logo.png';
2020
2121
let html = `<img src="${logoPath}" alt="ACME logo">`;
2222

Diff for: frontend/encore/dev-server.rst

+53-56
Original file line numberDiff line numberDiff line change
@@ -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,
1414
allowing 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),
1919
you'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-
3621
dev-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

Diff for: frontend/encore/installation.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ is the main config file for both Webpack and Webpack Encore:
5454

5555
.. code-block:: javascript
5656
57-
var Encore = require('@symfony/webpack-encore');
57+
const Encore = require('@symfony/webpack-encore');
5858
5959
// Manually configure the runtime environment if not already configured yet by the "encore" command.
6060
// It's useful when you use tools that rely on webpack.config.js file.

Diff for: frontend/encore/shared-entry.rst

-42
This file was deleted.

Diff for: frontend/encore/simple-example.rst

+8-40
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ application: it will *require* all of the dependencies it needs (e.g. jQuery or
1919
2020
import './styles/app.css';
2121
22-
// import $ from 'jquery';
23-
2422
Encore's job (via Webpack) is simple: to read and follow *all* of the ``require()``
2523
statements and create one final ``app.js`` (and ``app.css``) that contains *everything*
2624
your app needs. Encore can do a lot more: minify files, pre-process Sass/LESS,
@@ -35,7 +33,7 @@ of your project. It already holds the basic config you need:
3533
.. code-block:: javascript
3634
3735
// webpack.config.js
38-
var Encore = require('@symfony/webpack-encore');
36+
const Encore = require('@symfony/webpack-encore');
3937
4038
Encore
4139
// directory where compiled assets will be stored
@@ -130,6 +128,8 @@ filename(s) to render. This file is *especially* useful because you can
130128
:doc:`enable versioning </frontend/encore/versioning>` or
131129
:doc:`point assets to a CDN </frontend/encore/cdn>` without making *any* changes to your
132130
template: the paths in ``entrypoints.json`` will always be the final, correct paths.
131+
And if you use :doc:`splitEntryChunks() </frontend/encore/split-chunks>` (where Webpack splits the output into even
132+
more files), all the necessary ``script`` and ``link`` tags will render automatically.
133133

134134
If you're *not* using Symfony, you can ignore the ``entrypoints.json`` file and
135135
point to the final, built file directly. ``entrypoints.json`` is only required for
@@ -147,13 +147,13 @@ some optional features.
147147
Requiring JavaScript Modules
148148
----------------------------
149149

150-
Webpack is a module bundler, which means that you can ``require`` other JavaScript
150+
Webpack is a module bundler, which means that you can ``import`` other JavaScript
151151
files. First, create a file that exports a function:
152152

153153
.. code-block:: javascript
154154
155155
// assets/greet.js
156-
module.exports = function(name) {
156+
export default function(name) {
157157
return `Yo yo ${name} - welcome to Encore!`;
158158
};
159159
@@ -163,19 +163,19 @@ We'll use jQuery to print this message on the page. Install it via:
163163
164164
$ yarn add jquery --dev
165165
166-
Great! Use ``require()`` to import ``jquery`` and ``greet.js``:
166+
Great! Use ``import`` to import ``jquery`` and ``greet.js``:
167167

168168
.. code-block:: diff
169169
170170
// assets/app.js
171171
// ...
172172
173173
+ // loads the jquery package from node_modules
174-
+ var $ = require('jquery');
174+
+ import jquery from 'jquery';
175175
176176
+ // import the function from greet.js (the .js extension is optional)
177177
+ // ./ (or ../) means to look for a local file
178-
+ var greet = require('./greet');
178+
+ import greet from './greet';
179179
180180
+ $(document).ready(function() {
181181
+ $('body').prepend('<h1>'+greet('jill')+'</h1>');
@@ -185,37 +185,6 @@ That's it! If you previously ran ``encore dev --watch``, your final, built files
185185
have already been updated: jQuery and ``greet.js`` have been automatically
186186
added to the output file (``app.js``). Refresh to see the message!
187187

188-
The import and export Statements
189-
--------------------------------
190-
191-
Instead of using ``require()`` and ``module.exports`` like shown above, JavaScript
192-
provides an alternate syntax based on the `ECMAScript 6 modules`_ that includes
193-
the ability to use dynamic imports.
194-
195-
To export values using the alternate syntax, use ``export``:
196-
197-
.. code-block:: diff
198-
199-
// assets/greet.js
200-
- module.exports = function(name) {
201-
+ export default function(name) {
202-
return `Yo yo ${name} - welcome to Encore!`;
203-
};
204-
205-
To import values, use ``import``:
206-
207-
.. code-block:: diff
208-
209-
// assets/app.js
210-
- require('../styles/app.css');
211-
+ import './styles/app.css';
212-
213-
- var $ = require('jquery');
214-
+ import $ from 'jquery';
215-
216-
- var greet = require('./greet');
217-
+ import greet from './greet';
218-
219188
.. _multiple-javascript-entries:
220189

221190
Page-Specific JavaScript or CSS (Multiple Entries)
@@ -357,5 +326,4 @@ Encore supports many more features! For a full list of what you can do, see
357326
`Encore's index.js file`_. Or, go back to :ref:`list of Encore articles <encore-toc>`.
358327

359328
.. _`Encore's index.js file`: https://github.com/symfony/webpack-encore/blob/master/index.js
360-
.. _`ECMAScript 6 modules`: https://hacks.mozilla.org/2015/08/es6-in-depth-modules/
361329
.. _`WebpackEncoreBundle Configuration`: https://github.com/symfony/webpack-encore-bundle#configuration

Diff for: frontend/encore/split-chunks.rst

+7-6
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ To enable this, call ``splitEntryChunks()``:
2323
2424
2525
Now, each output file (e.g. ``homepage.js``) *may* be split into multiple file
26-
(e.g. ``homepage.js``, ``vendor~homepage.js``). This means that you *may* need to
27-
include *multiple* ``script`` tags (or ``link`` tags for CSS) in your template.
28-
Encore creates an :ref:`entrypoints.json <encore-entrypointsjson-simple-description>`
26+
(e.g. ``homepage.js`` & ``vendors-node_modules_jquery_dist_jquery_js.js`` - the
27+
filename of the second will be less obvious when you build for production). This
28+
means that you *may* need to include *multiple* ``script`` tags (or ``link`` tags
29+
for CSS) in your template. Encore creates an :ref:`entrypoints.json <encore-entrypointsjson-simple-description>`
2930
file that lists exactly which CSS and JavaScript files are needed for each entry.
3031

3132
If you're using the ``encore_entry_link_tags()`` and ``encore_entry_script_tags()``
@@ -37,9 +38,9 @@ tags as needed:
3738

3839
{#
3940
May now render multiple script tags:
40-
<script src="/build/runtime.js"></script>
41-
<script src="/build/vendor~homepage.js"></script>
42-
<script src="/build/homepage.js"></script>
41+
<script src="/build/runtime.js" defer></script>
42+
<script src="/build/vendors-node_modules_jquery_dist_jquery_js.js" defer></script>
43+
<script src="/build/homepage.js" defer></script>
4344
#}
4445
{{ encore_entry_script_tags('homepage') }}
4546

0 commit comments

Comments
 (0)