Skip to content
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

Expanding Autonomy #57

Open
tabuna opened this issue Jun 14, 2024 · 2 comments
Open

Expanding Autonomy #57

tabuna opened this issue Jun 14, 2024 · 2 comments

Comments

@tabuna
Copy link

tabuna commented Jun 14, 2024

Thank you for the work you’ve done. 🙏
I would like to discuss an idea: currently, this package is suitable only for Laravel projects, but not for their packages.

I think it would be great if we could use importmap for various packages, such as forums, admin panels, and so on.

At the moment, builds are usually done using Vite or Laravel Mix, as they are not tied to a specific project.
I believe it would be beneficial if we could perform these actions as a standalone resource. What do you think?

@tonysm
Copy link
Owner

tonysm commented Aug 13, 2024

Do you mean for package authors or app modules?

Package files are already supported via:

  • Package publishes assets to public/vendor/{package}/
  • Package adds a new pin line to routes/importmap.php that points to the package in /vendor/{package}/file.js

The Stimulus Laravel package is an example.

If you mean app modules (I saw the discussion in the rails-importmap about it), I think it's already supported, but the DX isn't great. You'd have to do something like:

  • Bind a new Importmap class (like this)
  • Create a new routes/{module}-importmap.php entrypoint then require it in the Service Provider so it registers the mapping (like here)
  • Here's the ugly part, you'd have to register the pins using the new binding key from the Service Provider, so if you bound the new Importmap as admin-importmap, you'd have to do resolve('admin-importmap)->pin(...)` instead of using the Facade
  • Then, when you're using the <x-importmap::tags> component on your admin template, you would have to pass the importmap down like <x-importmap::tags :importmap="resolve('admin-importmap')" /> so the mappings would be registered correctly

I do have some ideas on how to maybe improve this, but would also be open for contribution.

@tabuna
Copy link
Author

tabuna commented Aug 14, 2024

I'm not sure if I expressed myself clearly, and I want to ensure we're on the same page. What I mean is that it would be useful to have a more independent tool that is suitable for Laravel package authors.

For example, I would like to replace Mix with Importmap in the Orchid package. The idea is to create an importmap.php file in the root directory of the project, and then use the following command:

php vendor/bin/importmap

This would also apply to other commands like php artisan importmap:outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants