Skip to content

Commit 3267189

Browse files
committed
tweaks after proofread
1 parent 5b5cabc commit 3267189

File tree

1 file changed

+43
-41
lines changed

1 file changed

+43
-41
lines changed

frontend/asset_mapper.rst

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -262,33 +262,32 @@ outputs an `importmap`_:
262262
}
263263
}</script>
264264

265-
Import maps are a native browser feature. They work in all browsers thanks to
266-
a "shim" file that's included automatically by the AssetMapper component
267-
(all *modern* browsers `support them natively <https://caniuse.com/import-maps>`_).
268-
269-
When you import ``bootstrap`` from your JavaScript, the browser will look at
270-
the ``importmap`` and see that it should fetch the package from the URL.
265+
Import maps are a native browser feature. When you import ``bootstrap`` from
266+
JavaScript, the browser will look at the ``importmap`` and see that it should
267+
fetch the package from the associated path.
271268

272269
.. _automatic-import-mapping:
273270

274-
But where did the ``/assets/duck.js`` import entry come from? Great question!
271+
But where did the ``/assets/duck.js`` import entry come from? That doesn't live
272+
in ``importmap.php``. Great question!
275273

276274
The ``assets/app.js`` file above imports ``./duck.js``. When you import a file using a
277275
relative path, your browser looks for that file relative to the one importing
278276
it. So, it would look for ``/assets/duck.js``. That URL *would* be correct,
279277
except that the ``duck.js`` file is versioned. Fortunately, the AssetMapper component
280-
sees that import and adds a mapping from ``/assets/duck.js`` to the correct, versioned
278+
sees the import and adds a mapping from ``/assets/duck.js`` to the correct, versioned
281279
filename. The result: importing ``./duck.js`` just works!
282280

283-
The ``importmap()`` function also outputs an `ES module shim`_ so that older browsers
284-
understand impotmaps (see the :ref:`polyfill config <config-importmap-polyfill>`).
281+
The ``importmap()`` function also outputs an `ES module shim`_ so that
282+
`older browsers <https://caniuse.com/import-maps>`_ understand importmaps
283+
(see the :ref:`polyfill config <config-importmap-polyfill>`).
285284

286285
.. _app-entrypoint:
287286

288-
The "app" Entrypoint Preloading
289-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
287+
The "app" Entrypoint & Preloading
288+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
290289

291-
An "entrypoint" is the main JavaScript file that the browser will load,
290+
An "entrypoint" is the main JavaScript file that the browser loads,
292291
and your app starts with one by default::
293292

294293
// importmap.php
@@ -302,7 +301,7 @@ and your app starts with one by default::
302301

303302
.. _importmap-app-entry:
304303

305-
In addition to the importmap, the ``{{ importmap('app') }}`` function call in
304+
In addition to the importmap, the ``{{ importmap('app') }}`` in
306305
``base.html.twig`` outputs a few other things, including:
307306

308307
.. code-block:: html
@@ -338,7 +337,7 @@ and a specific language:
338337
hljs.highlightAll();
339338
340339
In this case, adding the ``highlight.js`` package to your ``importmap.php`` file
341-
won't work: whatever your importing - e.g. ``highlight.js/lib/core`` - needs to
340+
won't work: whatever you import - e.g. ``highlight.js/lib/core`` - needs to
342341
*exactly* match an entry in the ``importmap.php`` file.
343342

344343
Instead, use ``importmap:require`` and pass it the exact paths you need. This
@@ -397,7 +396,7 @@ Handling CSS
397396
The ability to import CSS files was introduced in Symfony 6.4.
398397

399398
CSS can be added to your page by importing it from a JavaScript file. The default
400-
``assets/app.js`` already imports the ``assets/styles/app.css`` file:
399+
``assets/app.js`` already imports ``assets/styles/app.css``:
401400

402401
.. code-block:: javascript
403402
@@ -416,7 +415,8 @@ the page as ``link`` tags in the order they were imported.
416415
Importing a CSS file is *not* something that is natively supported by
417416
JavaScript modules and normally causes an error. AssetMapper makes this
418417
work by adding an importmap entry for each CSS file that is valid, but
419-
does nothing (but the CSS file *is* included as a ``link`` tag).
418+
does nothing. AssetMapper adds a ``link`` tag for each CSS file, but when
419+
the JavaScript executes the ``import`` statement, nothing additional happens.
420420

421421
.. _asset-mapper-3rd-party-css:
422422

@@ -426,7 +426,7 @@ Handling 3rd-Party CSS
426426
Sometimes a JavaScript package will contain one or more CSS files. For example,
427427
the ``bootstrap`` package has a `dist/css/bootstrap.min.css file`_.
428428

429-
Fortunately, you can require CSS files in the same way as JavaScript files:
429+
You can require CSS files in the same way as JavaScript files:
430430

431431
.. code-block:: terminal
432432
@@ -471,6 +471,21 @@ for ``duck.png``:
471471
background-image: url('../images/duck-3c16d9220694c0e56d8648f25e6035e9.png');
472472
}
473473
474+
.. _asset-mapper-tailwind:
475+
476+
Using Tailwind CSS
477+
~~~~~~~~~~~~~~~~~~
478+
479+
To use the `Tailwind`_ CSS framework with the AssetMapper component, check out
480+
`symfonycasts/tailwind-bundle`_.
481+
482+
.. _asset-mapper-sass:
483+
484+
Using Sass
485+
~~~~~~~~~~
486+
487+
To use Sass with AssetMapper component, check out `symfonycasts/sass-bundle`_.
488+
474489
Lazily Importing CSS from a JavaScript File
475490
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
476491

@@ -485,7 +500,9 @@ the normal, "dynamic" import syntax:
485500
// ...
486501
487502
In this case, ``lazy.css`` will be downloaded asynchronously and then added to
488-
the page.
503+
the page. If you use a dynamic import to lazily-load a JavaScript file and that
504+
file imports a CSS file (using the non-dynamic ``import`` syntax), that CSS file
505+
will also be downloaded asynchronously.
489506

490507
Issues and Debugging
491508
--------------------
@@ -659,13 +676,13 @@ download them one-by-one as it discovers them. That would hurt performance.
659676
AssetMapper avoids this problem by outputting "preload" ``link`` tags.
660677
The logic works like this:
661678

662-
A) When you call ``importmap('app')`` in your template, the AssetMapper component
663-
looks at the ``assets/app.js`` file and finds all of the JavaScript files
664-
that it imports or files that those files import, etc.
679+
**A) When you call ``importmap('app')`` in your template**, the AssetMapper component
680+
looks at the ``assets/app.js`` file and finds all of the JavaScript files
681+
that it imports or files that those files import, etc.
665682

666-
B) It then outputs a ``link`` tag for each of those files with a ``rel="preload"``
667-
attribute. This tells the browser to start downloading those files immediately,
668-
even though it hasn't yet seen the ``import`` statement for them.
683+
**B) It then outputs a ``link`` tag** for each of those files with a ``rel="preload"``
684+
attribute. This tells the browser to start downloading those files immediately,
685+
even though it hasn't yet seen the ``import`` statement for them.
669686

670687
Additionally, if the :doc:`WebLink Component </web_link>` is available in your application,
671688
Symfony will add a ``Link`` header in the response to preload the CSS files.
@@ -755,7 +772,7 @@ Sure! See :ref:`Using Tailwind CSS <asset-mapper-tailwind>` or :ref:`Using Sass
755772
Can I use with TypeScript?
756773
~~~~~~~~~~~~~~~~~~~~~~~~~~
757774

758-
Sure!See :ref:`Using TypeScript <asset-mapper-ts>`.
775+
Sure! See :ref:`Using TypeScript <asset-mapper-ts>`.
759776

760777
Can I use with JSX or Vue?
761778
~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -774,21 +791,6 @@ files) with component, as those must be used in a build system. See the
774791
`UX Vue.js Documentation`_ for more details about using with the AssetMapper
775792
component.
776793

777-
.. _asset-mapper-tailwind:
778-
779-
Using Tailwind CSS
780-
------------------
781-
782-
To use the `Tailwind`_ CSS framework with the AssetMapper component, check out
783-
`symfonycasts/tailwind-bundle`_.
784-
785-
.. _asset-mapper-sass:
786-
787-
Using Sass
788-
----------
789-
790-
To use Sass with AssetMapper component, check out `symfonycasts/sass-bundle`_.
791-
792794
.. _asset-mapper-ts:
793795

794796
Using TypeScript

0 commit comments

Comments
 (0)