@@ -262,33 +262,32 @@ outputs an `importmap`_:
262
262
}
263
263
} </script >
264
264
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.
271
268
272
269
.. _automatic-import-mapping :
273
270
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!
275
273
276
274
The ``assets/app.js `` file above imports ``./duck.js ``. When you import a file using a
277
275
relative path, your browser looks for that file relative to the one importing
278
276
it. So, it would look for ``/assets/duck.js ``. That URL *would * be correct,
279
277
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
281
279
filename. The result: importing ``./duck.js `` just works!
282
280
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 >`).
285
284
286
285
.. _app-entrypoint :
287
286
288
- The "app" Entrypoint Preloading
289
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
287
+ The "app" Entrypoint & Preloading
288
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
290
289
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 ,
292
291
and your app starts with one by default::
293
292
294
293
// importmap.php
@@ -302,7 +301,7 @@ and your app starts with one by default::
302
301
303
302
.. _importmap-app-entry :
304
303
305
- In addition to the importmap, the ``{{ importmap('app') }} `` function call in
304
+ In addition to the importmap, the ``{{ importmap('app') }} `` in
306
305
``base.html.twig `` outputs a few other things, including:
307
306
308
307
.. code-block :: html
@@ -338,7 +337,7 @@ and a specific language:
338
337
hljs .highlightAll ();
339
338
340
339
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
342
341
*exactly * match an entry in the ``importmap.php `` file.
343
342
344
343
Instead, use ``importmap:require `` and pass it the exact paths you need. This
@@ -397,7 +396,7 @@ Handling CSS
397
396
The ability to import CSS files was introduced in Symfony 6.4.
398
397
399
398
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 ``:
401
400
402
401
.. code-block :: javascript
403
402
@@ -416,7 +415,8 @@ the page as ``link`` tags in the order they were imported.
416
415
Importing a CSS file is *not * something that is natively supported by
417
416
JavaScript modules and normally causes an error. AssetMapper makes this
418
417
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.
420
420
421
421
.. _asset-mapper-3rd-party-css :
422
422
@@ -426,7 +426,7 @@ Handling 3rd-Party CSS
426
426
Sometimes a JavaScript package will contain one or more CSS files. For example,
427
427
the ``bootstrap `` package has a `dist/css/bootstrap.min.css file `_.
428
428
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:
430
430
431
431
.. code-block :: terminal
432
432
@@ -471,6 +471,21 @@ for ``duck.png``:
471
471
background-image : url (' ../images/duck-3c16d9220694c0e56d8648f25e6035e9.png' );
472
472
}
473
473
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
+
474
489
Lazily Importing CSS from a JavaScript File
475
490
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
476
491
@@ -485,7 +500,9 @@ the normal, "dynamic" import syntax:
485
500
// ...
486
501
487
502
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.
489
506
490
507
Issues and Debugging
491
508
--------------------
@@ -659,13 +676,13 @@ download them one-by-one as it discovers them. That would hurt performance.
659
676
AssetMapper avoids this problem by outputting "preload" ``link `` tags.
660
677
The logic works like this:
661
678
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.
665
682
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.
669
686
670
687
Additionally, if the :doc: `WebLink Component </web_link >` is available in your application,
671
688
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
755
772
Can I use with TypeScript?
756
773
~~~~~~~~~~~~~~~~~~~~~~~~~~
757
774
758
- Sure!See :ref: `Using TypeScript <asset-mapper-ts >`.
775
+ Sure! See :ref: `Using TypeScript <asset-mapper-ts >`.
759
776
760
777
Can I use with JSX or Vue?
761
778
~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -774,21 +791,6 @@ files) with component, as those must be used in a build system. See the
774
791
`UX Vue.js Documentation `_ for more details about using with the AssetMapper
775
792
component.
776
793
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
-
792
794
.. _asset-mapper-ts :
793
795
794
796
Using TypeScript
0 commit comments