Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Hello AssetMapper Documentation #18370

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

Closed
wants to merge 14 commits into from
Prev Previous commit
Next Next commit
fixes
  • Loading branch information
weaverryan committed Jun 4, 2023
commit c6fc37296f5315471cf120c11062c5d94fe44022
7 changes: 3 additions & 4 deletions frontend.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Symfony ships with two options for handling the CSS and JavaScript in your app:
* :ref:`Webpack Encore <frontend-webpack-encore>` is a powerful tool built with Node
on top of `Webpack`_ that allows you to write modern CSS & JavaScript and handle
things like JSX (React), Vue or TypeScript. It's the recommended option for
new Symfony apps.
new Symfony applications.

* :ref:`AssetMapper <frontend-asset-mapper>`, is a production-ready simpler alternative
to Webpack Encore that runs entirely in PHP. It's currently experimental.
Expand Down Expand Up @@ -106,7 +106,7 @@ Full API
.. _frontend-asset-mapper:

AssetMapper
------------
-----------

AssetMapper is an alternative to Webpack Encore that runs entirely in PHP
without any complex build steps. It leverages the ``importmap`` feature of
Expand Down Expand Up @@ -135,8 +135,7 @@ Other Front-End Articles
frontend/encore/installation
frontend/encore/simple-example
frontend/encore/*
frontend/asset_mapper/installation
frontend/asset_mapper/usage
frontend/asset_mapper
frontend/asset_mapper/*
frontend/*
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bottom of https://symfony.com/doc/current/frontend.html is currently "wonky". I think the intention was for the the first, :hidden toctree to "load" all of the encore stuff into the toctree... and then this bottom toctree would only load anything "remaining". In practice, it would render everything.

So, I reduced this to just ONE toctree, which is :hidden:. The 2 documents that are outside of encore/* were added manually under the Other Front-End Articles section.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fun fact, including documents in a toctree entry is no longer relevant with the PHP based parser IIRC

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That IS a fun fact, thank you!


Expand Down
15 changes: 7 additions & 8 deletions frontend/asset_mapper.rst
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ directory.

If you create an ``assets/images/duck.png`` file, you can reference it in a template with:

.. code-block:: twig
.. code-block:: html+twig

<img src="{{ asset('images/duck.png') }}">

Expand Down Expand Up @@ -118,7 +118,7 @@ for ``duck.png``:
}

Debugging: Seeing All Mapped Assets
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

To see all of the mapped assets in your app, run:

Expand Down Expand Up @@ -188,7 +188,7 @@ Twig function (see :ref:`import 'app' <importmap-app-entry>`). So, this code wil
Unlike in Node, in the browser environment, the extension is required.

Importing 3rd Party JavaScript Packages
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Suppose you want to use an `npm package`_, like `bootstrap`_. Technically,
this can be done by importing its full URL, like from a CDN:
Expand Down Expand Up @@ -611,7 +611,7 @@ Frequently Asked Questions
--------------------------

Does AssetMapper Combine Assets?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Nope! But that's because this is no longer necessary!

Expand All @@ -625,7 +625,7 @@ all of your other assets.
See :ref:`Optimization <optimization>` for more details.

Does AssetMapper Minify Assets?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Nope! Minifying or compressing assets *is* important, but can easily be
done by your web server or a service like Cloudflare. See
Expand Down Expand Up @@ -665,7 +665,7 @@ If you *do* need to support very old browsers, you should use a tool like
The ``importmap`` feature **is** shimmed to work in **all** browsers by AssetMapper.
However, the shim doesn't work with "dynamic" imports:

.. code-block:: js
.. code-block:: javascript

// this works
import { add } from './math.js';
Expand Down Expand Up @@ -832,7 +832,7 @@ This means you can render these assets in your templates using the
<link rel="stylesheet" href="{{ asset('bundles/babdevpagerfanta/css/pagerfanta.css') }}">

Actually, this path - ``bundles/babdevpagerfanta/css/pagerfanta.css`` - already
works in apps *without* AssetMapper, because the ``assets:install`` command copies
works in applications *without* AssetMapper, because the ``assets:install`` command copies
the assets from bundles into ``public/bundles/``. However, when AssetMapper is
enabled, the ``pagerfanta.css`` file will automatically be versioned! It will
output someting like:
Expand Down Expand Up @@ -1016,7 +1016,6 @@ This will force the AssetMapper to re-calculate the content of all files.
.. _importmap: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap
.. _bootstrap: https://www.npmjs.com/package/bootstrap
.. _es module shim: https://www.npmjs.com/package/es-module-shims
.. _npmjs.com: https://www.npmjs.com/
.. _jsdelivr.com: https://www.jsdelivr.com/
.. _highlight.js: https://www.npmjs.com/package/highlight.js
.. _class syntax: https://caniuse.com/es6-class
Expand Down