'How to integrate TailwindCSS in a Laravel package?

Usually, when I use Tailwind in Laravel, I would install it like so:

$ npm install -D tailwindcss postcss autoprefixer
$ npx tailwindcss init
/* in the app.css file. */
@tailwind base;
@tailwind components;
@tailwind utilities;

I can not find any documentation on integrating it in a Laravel package? The main points of confusion for me are currently:

  1. Do I need to publish the assets manually, or can it be done automatically?
  2. Do I need to publish the assets, or can I use them from the package directory?
  3. How can I use a custom tailwind.config.js file?

These things can be done by manually publishing the files, but that does not seem to be the correct solution. Any guidance would be appreciated.



Solution 1:[1]

The Laravel documentation suggest to publish assets directly to the public folder. This would imply that you compile them before publishing.

Since what you are looking for may be not supported by Laravel directly out of the box and is a bit more complex you can find inspiration by looking at the Laravel Breeze codebase, which publishes multiple assets using tailwind as well.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jonathan