Symfony gives you the flexibility to choose any front-end tools you want. There are generally two approaches:
- :ref:`building your HTML with PHP & Twig <frontend-twig-php>`;
- :ref:`building your frontend with a JavaScript framework <frontend-js>` like React, Vue, Svelte, etc.
Both work great - and are discussed below.
Symfony comes with two powerful options to help you build a modern and fast frontend:
- :ref:`AssetMapper <frontend-asset-mapper>` (recommended for new projects) runs entirely in PHP, doesn't require any build step and leverages modern web standards.
- :ref:`Webpack Encore <frontend-webpack-encore>` is built with Node.js on top of Webpack.
Production Ready? | yes | yes |
Stable? | yes | yes |
Requirements | none | Node.js |
Requires a build step? | no | yes |
Works in all browsers? | yes | yes |
Supports Stimulus/UX | yes | yes |
Supports Sass/Tailwind | :ref:`yes <asset-mapper-tailwind>` | yes |
Supports React, Vue, Svelte? | yes :ref:`[1] <ux-note-1>` | yes |
Supports TypeScript | :ref:`yes <asset-mapper-ts>` | yes |
Removes comments from JavaScript | no | yes |
Removes comments from CSS | no | no |
Versioned assets | always | optional |
Can update 3rd party packages | yes | no :ref:`[2] <ux-note-2>` |
[1] Using JSX (React), Vue, etc with AssetMapper is possible, but you'll need to use their native tools for pre-compilation. Also, some features (like Vue single-file components) cannot be compiled down to pure JavaScript that can be executed by a browser.
[2] If you use npm
, there are update checkers available (e.g. npm-check
).
AssetMapper is the recommended system for handling your assets. It runs entirely
in PHP with no complex build step or dependencies. It does this by leveraging
the importmap
feature of your browser, which is available in all browsers thanks
to a polyfill.
:doc:`Read the AssetMapper Documentation </frontend/asset_mapper>`
.. screencast:: Do you prefer video tutorials? Check out the `Webpack Encore screencast series`_.
Webpack Encore is a simpler way to integrate Webpack into your application. It wraps Webpack, giving you a clean & powerful API for bundling JavaScript modules, pre-processing CSS & JS and compiling and minifying assets.
:doc:`Read the Encore Documentation </frontend/encore/index>`
Once you've installed AssetMapper or Webpack Encore, it's time to start building your front-end. You can write your JavaScript however you want, but we recommend using Stimulus, Turbo and a set of tools called Symfony UX.
To learn about Stimulus & the UX Components, see the StimulusBundle Documentation
If you want to use a front-end framework (Next.js, React, Vue, Svelte, etc), we recommend using their native tools and using Symfony as a pure API. A wonderful tool to do that is API Platform. Their standard distribution comes with a Symfony-powered API backend, frontend scaffolding in Next.js (other frameworks are also supported) and a React admin interface. It comes fully Dockerized and even contains a web server.