// composer.json
{
"require": {
"php": ">=8.3",
"ext-ctype": "*",
"ext-iconv": "*",
"babdev/pagerfanta-bundle": "^4.0", // v4.4.0
"doctrine/doctrine-bundle": "^2.7", // 2.11.1
"doctrine/doctrine-migrations-bundle": "^3.2", // 3.3.0
"doctrine/orm": "^2.12", // 2.17.3
"knplabs/knp-time-bundle": "^2.2", // v2.2.0
"pagerfanta/doctrine-orm-adapter": "^4.0", // v4.2.0
"pagerfanta/twig": "^4.0", // v4.2.0
"stof/doctrine-extensions-bundle": "^1.7", // v1.10.1
"symfony/asset": "7.0.*", // v7.0.0
"symfony/asset-mapper": "7.0.*", // v7.0.2
"symfony/console": "7.0.*", // v7.0.2
"symfony/dotenv": "7.0.*", // v7.0.2
"symfony/flex": "^2", // v2.4.3
"symfony/framework-bundle": "7.0.*", // v7.0.2
"symfony/http-client": "7.0.*", // v7.0.2
"symfony/messenger": "7.0.*", // v7.0.1
"symfony/monolog-bundle": "^3.0", // v3.10.0
"symfony/runtime": "7.0.*", // v7.0.0
"symfony/scheduler": "7.0.*", // v7.0.0
"symfony/twig-bundle": "7.0.*", // v7.0.0
"symfony/ux-turbo": "^2.0", // v2.13.2
"symfony/yaml": "7.0.*", // v7.0.0
"twig/extra-bundle": "^2.12|^3.0", // v3.8.0
"twig/twig": "^2.12|^3.0" // v3.8.0
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.4", // 3.5.1
"symfony/debug-bundle": "7.0.*", // v7.0.0
"symfony/maker-bundle": "^1.41", // v1.52.0
"symfony/stopwatch": "7.0.*", // v7.0.0
"symfony/web-profiler-bundle": "7.0.*", // v7.0.2
"zenstruck/foundry": "^1.21" // v1.36.1
}
}
11 Comments
Hello!
I am using premium plugins from GSAP. They are not available on CDN and so, can not be installed with importmap:require. How can I continue to use them?
Thx!
Hey @be_tnt
That's a very good question, sadly I don't know the answer, I've never had that problem before. Have you tried opening an issue on the Asset Mapper GitHub repository?
I will. Thx!
If I have the following custom function call on certain pages (not all):
How can I convert this to use AssetMapper, given that
'time-entries-summary-style'is a Webpack entry mapped to an SCSS file like this in the Webpack configuration?What steps are necessary to replace
encore_entry_link_tagswith the AssetMapper equivalent while ensuring it works correctly only on specific pages?Hey @ahmedbhs ,
I think this blog post might be interested for you: https://symfony.com/blog/upgrading-symfony-websites-to-assetmapper - it highlights some migration steps from Encore to AssetMapper.
But in particular, to replace
{{ encore_entry_link_tags('time-entries-summary-style') }}with the AssetMapper I think you should follow these steps:The Webpack Encore entries are so called AssetMapper entrypoints. You need to convert your entries into entrypoints1-to-1. You need to do this manually by editing the importmap.php file. See the blog post I linked above for more examples.
Fix imports in your assets. Now, every time you import files, you must include the file extension. Once again see the example from the blog post.
Replace
encore_entry_link_tags()calls in Twig templates withimportmap()ones.Enable SCSS Compilation in AssetMapper. By default, AssetMapper doesn't process SCSS files. You’ll need to configure it to use the symfonycasts/sass-bundle SCSS processor for this. Though think well if you still need Sass, because native CSS supports a lot of things and most probably you can finally convert your SCSS files into plain CSS files. Then you will simplify your setup a lot.
So. once again, I think that blog post will answer most of your questions, so make sure to read it in full to make the smooth migration. And sorry for the long reply on it!
I hope it helps!
Cheers!
Hi Ryan, I'm following this course to upgrade my app from 6.2 to 7.1. I have been able to follow all the steps discussed in the video without any problem. Unfortunately when I try to import jquery-ui (it's not mentioned in the video, I know) I can't get it to work. I have searched for a solution on the internet without good results. Is it possible that this is too new to find any solution? If not, how could I find a solution to my problem?
the error I'm getting in the console is:
Instead, if I can use jQuery without difficulties in the project, for example, if a
console.log($(".myclass");and of course, everything works correctly in webpackencore, but I want to be up to date with symfony and assetmapper.Any information on this is welcome, thank you very much.
Hey @Juan-D
Are you using Webpack or Asset Mapper?
Cheers!
As I say in my query, I am upgrading from Symfony 6.4 to 7.1 and changing webpack to activemapper. I have gone from 6.2 to 6.4 and from 6.4 to 7.1. I have been able to follow the tutorial without problem except for jquery-ui.
Regards!
Hey Juan,
Your upgrading strategy looks good to me. However, probably would be better to finish the upgrade first, and then, in a new PR, migrate from WebpackEncore to AssetMapper. It would simplify things for upgrading for you, and also it will be more obvious for you if you could easily migrate your project to AssetMapper or it requires more changes in your code.
Ideally, I would recommend you to get rid of jQuery completely in your project. jQuery is not recommended anymore as most of things can be easily done natively in the modern JS now. You can reference this website to see how you can replace jQuery calls with modern native JS: https://youmightnotneedjquery.com/
But if your code is tied very much to jQuery - I understand you, and it would require you some time to refactor. But it's difficult to say what's wrong in your code, because it depends on how (and where) you use jQuery. I don remember for sure, but it might be so that you can't use jQuery globally anymore. But in modern JS you should be able to import it like this:
Or in case of the AssetMapper, you will need to install the package with
bin/console importmap:install jqueryand then in the import specify the exact path to the jquery file to import it correctly, something likeimport $ from './path/to/vendor/path/to/jquery.js'This should be the first step, and you need to make sure jQuery works for you this way. When it works for you, you can try to do the same with
jquery-ui, i.e. install it and import from the specific path where it was installed (I'm not sure if you can import everything at once, probably you would need to be more specific about what to import, e.g.import './path/to/vendor/jquery-ui/ui/widgets/datepicker.js'). It might be so that you may need to import both jquery and jquery-ui, i.e. import jquery first because jquery-ui may need that already. And in theory it should work, but if not - probably because jquery-ui requires the jquery to be globally available, not only for this file scope. And if so, this is a bad practice, but you may try to make the imported jquery global withwindow.$ = window.jQuery = $;. Once again, it's a bad practice, but it might work as a temporary solution before you get rid of jQuery completely.Also, please take a look at the official docs: https://symfony.com/doc/current/frontend/asset_mapper.html#global-variables-like-jquery - this should help as well.
I hope that helps!
Cheers!
Hello Victor,
Of course what you mention is the first thing I did. I have not given many explanations before because I wanted to get to the crux of the question directly. But I have carried out the entire update process in a new branch of my project called update. First I updated the framework completely, then the recipes and then I made the necessary adjustments so that everything worked. Now I'm with the js part, and I haven't had any problems until getting to jQuery-ui. As I mentioned, jqyery is imported without problems but as soon as I do "... importmap:require jquery-ui" when I do the import in my js file, the error mentioned appears, "jQuery is not defined". The first thing I did before anything was to consult the official documentation that you mention, to include "window.$=window.jQuery=$" but this does not work for me. And I have verified that I can use jquery in other ways, although in my case, it is with datepicker, but with autocomplete, although I suppose it does not matter which component to use since it is also part of jquery-ui. I had thought that perhaps importing the component I need explicitly could work, but it is something else that still fails, I imported "jquery-ui/ui/widgets/autocomplete" but this has not worked either.
On the other hand, you are right, I have a fairly strong dependency on jquery since I use other components through jquery, such as owl.carousel, but the import does not work either, but I will try to solve the problem first with jquery-ui and Then I will go to owl.carousel. I think it is related, and if I solve one problem the other will be solved.
Thanks for the help.
Greetings.
Hey @Juan-D
Have you tried to define the
jQueryas a global variable? It should happen before loading any other dependency. My guess is thejquery-uiplugin it's badly written, as many jquery plugins are, they assume that a globaljQueryvariable already existsCheers!
"Houston: no signs of life"
Start the conversation!