Chapters
32 Chapters
|
4:16:27
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "4.x-dev", // 4.x-dev
"doctrine/doctrine-bundle": "^2.10", // 2.12.x-dev
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.4.x-dev
"doctrine/orm": "^2.16", // 2.18.x-dev
"knplabs/knp-time-bundle": "dev-main", // dev-main
"pagerfanta/doctrine-orm-adapter": "4.x-dev", // 4.x-dev
"pagerfanta/twig": "4.x-dev", // 4.x-dev
"symfony/asset": "6.4.*", // 6.4.x-dev
"symfony/asset-mapper": "6.4.*", // 6.4.x-dev
"symfony/console": "6.4.x-dev", // 6.4.x-dev
"symfony/dotenv": "6.4.x-dev", // 6.4.x-dev
"symfony/flex": "^2", // 2.x-dev
"symfony/form": "6.4.x-dev", // 6.4.x-dev
"symfony/framework-bundle": "6.4.x-dev", // 6.4.x-dev
"symfony/monolog-bundle": "^3.0", // dev-master
"symfony/runtime": "6.4.x-dev", // 6.4.x-dev
"symfony/security-csrf": "6.4.x-dev", // 6.4.x-dev
"symfony/stimulus-bundle": "2.x-dev", // 2.x-dev
"symfony/twig-bundle": "6.4.x-dev", // 6.4.x-dev
"symfony/ux-autocomplete": "2.x-dev", // 2.x-dev
"symfony/ux-live-component": "2.x-dev", // 2.x-dev
"symfony/ux-turbo": "2.x-dev", // 2.x-dev
"symfony/ux-twig-component": "2.x-dev", // 2.x-dev
"symfony/validator": "6.4.x-dev", // 6.4.x-dev
"symfony/web-link": "6.4.*", // 6.4.x-dev
"symfony/yaml": "6.4.x-dev", // 6.4.x-dev
"symfonycasts/dynamic-forms": "dev-main", // dev-main
"symfonycasts/tailwind-bundle": "dev-main", // dev-main
"tales-from-a-dev/flowbite-bundle": "dev-main", // dev-main
"twig/extra-bundle": "^2.12|^3.0", // 3.x-dev
"twig/twig": "^2.12|^3.0" // 3.x-dev
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.6.x-dev
"phpunit/phpunit": "^9.5", // 9.6.x-dev
"symfony/browser-kit": "6.4.*", // 6.4.x-dev
"symfony/css-selector": "6.4.*", // 6.4.x-dev
"symfony/debug-bundle": "6.4.x-dev", // 6.4.x-dev
"symfony/maker-bundle": "^1.51", // dev-main
"symfony/panther": "^2.1", // v2.1.1
"symfony/phpunit-bridge": "7.1.x-dev", // 7.1.x-dev
"symfony/stopwatch": "6.4.x-dev", // 6.4.x-dev
"symfony/web-profiler-bundle": "6.4.x-dev", // 6.4.x-dev
"zenstruck/browser": "1.x-dev", // 1.x-dev
"zenstruck/foundry": "^1.36" // 1.x-dev
}
}
What JavaScript libraries does this tutorial use?
// importmap.php
return [
'app' => [
'path' => './assets/app.js',
'entrypoint' => true,
],
'js-confetti' => [
'version' => '0.11.0',
],
'@hotwired/stimulus' => [
'version' => '3.2.2',
],
'@symfony/stimulus-bundle' => [
'path' => './vendor/symfony/stimulus-bundle/assets/dist/loader.js',
],
'tom-select' => [
'version' => '2.3.1',
],
'tom-select/dist/css/tom-select.default.css' => [
'version' => '2.3.1',
'type' => 'css',
],
'@hotwired/turbo' => [
'version' => '7.3.0',
],
'stimulus-popover' => [
'version' => '6.2.0',
],
'debounce' => [
'version' => '1.2.1',
],
'turbo-view-transitions' => [
'version' => '0.3.0',
],
'stimulus-use' => [
'version' => '0.52.1',
],
'flowbite' => [
'version' => '2.2.1',
],
'@popperjs/core' => [
'version' => '2.11.8',
],
'flowbite-datepicker' => [
'version' => '1.2.6',
],
];
18 Comments
Hello, i'm really enjoying asset-mapper now, there is one thing i'm missing it is the reload of a page when a change is made in one template (or css , js), is there a way to achieve this ? or should i combine a vite or webpack encore associated with it ?
Hey Yoyo,
You’re right, out of the box, AssetMapper doesn't provide automatic page reloading when a file (like a Twig template, CSS, or JS file) changes. It's designed to be lightweight and doesn't include a dev server like Vite or Webpack Encore does.
I think it's possible to achieve autmatic reload, though personally I've never tried that. Take a look at the browser-sync NPM package. You will need to install it via Node, so it means you still would need to have node installed, but for local dev env it should be ok I think. And in theory, something like this should work:
Let me know if that helped :)
Cheers!
Oh nice great idea thanks a lot for your help !
You're welcome! I hope that will work that way. Feel free to share a working solution with others if that will be a different from what I described, it may be useful for others too I think :)
Cheers!
Good morning all,
because i really love asset mapper, i played around with it the last weeks and i hoped to get a solution for a little issue in my IDE with this LAST Stack.
I use PhpStorm, latest version but i never get autosuggestions/autocompletion for assets. For example this beautyfull Space Inviters Logo img-tag. If i hover over {{ asset('images/logo.png') }} in my twig template and everywhere, Phpstorm just tells me "Missing asset".
How can i fix this?
JD
Hey @Johann!
💯 me too. I believe this is something that will need to be updated with the Symfony + PhpStorm plugin. It looks like there's an issue about it - https://github.com/Haehnchen/idea-php-symfony2-plugin/issues/2236 and the author has been pretty responsive and supportive for AssetMapper support. So hopefully it can be added :).
Cheers!
Hi !
I find Asset mapper really easy to use compared to webpack but I have one problem, how can I import a private repository ? I'm using Tiptap editor with my app and I want to import some pro extensions. But I cannot find anything in the asset mapper doc about importing from private repository protected with a private token (via .npmrc file) as explained the tip tap documentation.
Is there a proper way to do it ?
Also, I was wondering why asset mapper is sometimes not requiring all the files of the package, for example I required katex and it only added a main js file, not the folders containing css and others js files I need (/contribs for exemple). I required them easily by specifying paths in the importmap command. Why with some packages it gets all the files and others only one ? Is there a mistake in my way of importing packages or understanding it at least ? Or si it something related to the package configuration ?
Thank you very much again for all the awesome and affordable courses !
Hey Hugo-Le-Goff,
Yeah, good question! And as always, it's a tradeoff. AssetMapper currently does not directly support downloading assets from private repositories, as it relies on GitHub repository URLs or local paths to fetch assets. However, there are a few workarounds you can use:
Use a Pre-Fetched Asset: Download the private repository manually (or using npm with your .npmrc file) and place the required assets in a folder in your project. Then, you can map the assets in your assets/ directory and include them in the importmap.
IIRC you can extend AssetMapper with a custom Command. You could create a custom Symfony console command or script to use npm or yarn to fetch the private package using your .npmrc configuration or copy the relevant files into the assets/ folder for Asset Mapper to handle.
Serve private assets via a CDN. If your private repository allows it, upload the required files to a private or authenticated CDN and reference them directly in your project via URLs.
Unfortunately, Asset Mapper's design intentionally avoids dependency on npm or similar tools to keep things lightweight, but this means it doesn't natively support features like .npmrc integration.
I haven't done those workarounds myself but IIRC they should be a valid solution with AssetMapper. Otherwise, you may still need to consider something more complex like Webpack Encore.
I hope that helps!
Cheers!
I also ran into an issue in dev where assets were returning a 404 due to nginx config.
The offender was
A useful config in production, but in dev, it means assets are served directly, bypassing symfony's listener to rewrite the path.
Hey @Nicolas-S
Good catch, yes, that causes problems with the dev environment. From my point of view, it will be good to add some check for static file exist, and if it does not exist, then pass it to the listener.
Cheers!
I'm not sure what's going on but after running composer require symfony/asset, my browser is getting 404 for all assets. I can run asset-map:compile and then the assets load just fine.
At first I thought this meant I had APP_ENV set to prod, but that's not it. I have confirmed that it is set to dev.
I did set up a docker container to run this project instead of using symfony serve. Could that be a factor in this?
Hey @kinadian!
I might know what's going on :). If you open a 404 URL in your browser, what do you see? Is it a Symfony 404? Or a generic 404 from your web server? The key to loading assets in dev is that the asset URLs need to be processed through Symfony. In other words, when a request is made to
/assets/app-abcd123.js, that request needs to be processed by Symfony. Sometimes a web server will, by default, see the.jsand only look for that physical file (then trigger a 404 if it's not found). If I'm correct, check the rewrite rules on your web server. This won't be an issue on production, as you've seen, but you'll definitely want to get this working locally.Cheers!
Hi @weaverryan!
Thank you. I asked a colleague to help. We ended up getting it fixed by installing symfony/apache-pack. This added an .htaccess file which changes apache's behaviour to let the request get processed by Symfony instead of returning a 404.
You were right, the 404 was a generic one from apache, not the Symfony 404 page.
Nice work! If you're using Apache, that is 100% the correct thing to do. I'm happy you got it sorted. Now, onward :)
With asset-mapper v.6.4 you may expect to not see the correct background color (i.e. skyblue).
In this case: try to remove comments in app.js (yes... the comments), remove public/asset directory and relaunch symfony serve command.
Thanks Ryan!
Thanks for sharing this! There was a but introduced in some version of AssetMapper related to the comment. I believe that should be fixed in 6.4.4 and 7.0.4, which will release very shortly after this comment.
Cheers!
Hey @weaverryan
The Asset Mapper looks really cool and I'm almost convinced to use it instead of Webpack Encore. The only thing that's holding me back, is that I do not see any examples or documentation on how to add integrity hashes for styles/scripts. Is this possible with the Asset Mapper?
Regards,
YT
Hey @Senet!
Ha! I like the challenge - let's see if we can get you the rest of the way there :).
You're right to catch this. It is not yet implemented - we did a LOT for 6.4 (and this was on my list), but it didn't quite happen. It became less of a priority because AssetMapper 6.4 (unlike 6.3) doesn't rely on serving content from CDNs. However, I recognize that some people may still want integrity hashes even if their assets are being served from the same hostname or perhaps if you use AssetMapper but still offload the serving of the files to your own CDN (am I listing one of your use-cases accurately)?
So right now, there is no hook in AssetMapper to add those, though it should be super easy to add. AssetMapper already knows the content of each asset and is responsible for rendering the script and link tags... so I can't really see a problem. However (and I'm not an expert at all on this topic), while we an add an integrity hash to any link or script tags on the page, if
app.jshasimport './foo.js', there is no mechanism currently to enforce an integrity hash on foo.js. You can read some discussion about it here - https://github.com/WICG/import-maps/issues/221. But even in that discussion, people are mainly talking about the importance of this when referencing assets on CDNs... and AssetMapper doesn't refer to CDN URLs. So, overall, I'm not sure HOW needed integrity hashes are... but I recognize that people (beyond you) will likely ask about this also.Cheers!
"Houston: no signs of life"
Start the conversation!