AssetMapper
Bredhis opened this issue ยท 6 comments
Hello @Kreyu,
I really like the direction this project is going in and for the great documentation at this early stage, one can only applaud.
Unfortunately, my problem is that the project I want to integrate this bundle into uses AssetMapper and not yarn/npm.
I have not been able to integrate the bundles assets into the importmap.php
.
Would it be possible to use this bundle together with the AssetMapper at the moment?
Hey @Bredhis, thank you for the kind words ๐
Personally, I've never used the AssetMapper before, but after some reading, I've added necessary stuff to the bundle (based on this article) in the #43 PR. I'll test it further tomorrow and release a new version.
If you wish to check if those changes are enough, please require the kreyu/data-table-bundle:dev-feature/asset-mapper
version, any feedback would help massively.
Hey @Kreyu ๐
Wow, thank you so much for your quick response!
I have installed everything fresh. But unfortunately I get the same error as yesterday, namely this:
An exception has been thrown during the rendering of a template ("Could not find an asset mapper path that points to the "personalization" controller in package "kreyu/data-table-bundle", defined in controllers.json.").
I've tried to investigate a little and the only package in my importmap.php
that does not refer to a URL but follows a path is the stimulus-bundle
. So I took a look at their package.json
.
My guess is what is missing in your bundles package.json
are two lines:
"importmap": { [โฆ], "@kreyu/data-table-bundle": "path:%PACKAGE%/controllers/batch.js", "@kreyu/data-table-bundle": "path:%PACKAGE%/controllers/personalization.js", }
sortablejs
gets added to the importmap.php
just fine. ๐
Hey, thanks for the response!
I've checked multiple Symfony UX bundles, and looks like providing individual controllers in the importmap
is not necessary. The path is provided by the bundle extension class, like so:
// src/DependencyInjection/KreyuDataTableExtension.php
if ($this->isAssetMapperAvailable($container)) {
$container->prependExtensionConfig('framework', [
'asset_mapper' => [
'paths' => [
__DIR__ . '/../../assets/controllers' => '@kreyu/data-table-bundle',
],
],
]);
}
Without this part, the error you're describing is raised. The only way I was able to reproduce this, was installing current release, then requiring dev-feature/asset-mapper
version without clearing cache (which is weird, since composer typically clears cache at the end) - since the configuration is cached.
After clearing cache, the mapping seems to be working properly:
$ bin/console debug:asset-map
Asset Mapper Paths
------------------
--------------------------------------------------- --------------------------
Path Namespace prefix
--------------------------------------------------- --------------------------
vendor/symfony/ux-autocomplete/assets/dist @symfony/ux-autocomplete
vendor/symfony/stimulus-bundle/assets/dist @symfony/stimulus-bundle
vendor/symfony/ux-turbo/assets/dist @symfony/ux-turbo
vendor/kreyu/data-table-bundle/assets/controllers @kreyu/data-table-bundle <<<<<
assets
--------------------------------------------------- --------------------------
Mapped Assets
-------------
---------------------------------------------- ---------------------------------------------------
Logical Path Filesystem Path
---------------------------------------------- ---------------------------------------------------
@symfony/ux-autocomplete/controller.js vendor/symfony/ux-autoc...sets/dist/controller.js
@symfony/stimulus-bundle/controllers.js vendor/symfony/stimulus...ets/dist/controllers.js
@symfony/stimulus-bundle/loader.js vendor/symfony/stimulus...e/assets/dist/loader.js
@symfony/ux-turbo/turbo_controller.js vendor/symfony/ux-turbo...ist/turbo_controller.js
@symfony/ux-turbo/turbo_stream_controller.js vendor/symfony/ux-turbo...bo_stream_controller.js
@kreyu/data-table-bundle/personalization.js vendor/kreyu/data-table...lers/personalization.js <<<<<
@kreyu/data-table-bundle/batch.js vendor/kreyu/data-table...ts/controllers/batch.js <<<<<
Can you please confirm that this is not an issue related with the caching?
Hey! I am very sorry for the extra work I have caused and I feel a bit stupid now.
Even if it wasn't the Symfony cache, your hint was right. The project is in a Docker container and although I have made a new deploy, this cache caused the trouble. So I deleted the image, rebuilt it completely and tadaa, it works. Normally the error messages are a bit clearer, so I know immediately that the vendor directory is not up-to-date. I'm sorry that I didn't think that far ahead and didn't tried basic stuff like this before writing here.
Have a great start to the week!
Hey! No worries, I'm happy that it works, thanks for your time ๐
I'm gonna tag a new release, and hope you'll find the bundle useful.
Cheers!
Available in version 0.15