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

AssetMapper / TailwindBundle compilation #475

Open
Spomky opened this issue Sep 28, 2023 · 7 comments
Open

AssetMapper / TailwindBundle compilation #475

Spomky opened this issue Sep 28, 2023 · 7 comments

Comments

@Spomky
Copy link

Spomky commented Sep 28, 2023

Hi @dunglas,

Many thanks for the last update of this repository. It works like a charm and I was able to run a demo quite easily.
The only problem I encountered was the absence of compiled assets. I recently turned to AssetMapper and TailwindBundle and needed to run the folowing lines:

In dev mode:

php bin/console importmap:update
php bin/console tailwind:build # --watch

In production

php bin/console tailwind:build --minify
php bin/console asset-map:compile

I am wondering if it is possible to conditionally call these commands (TBH I don't know how to determine they exist).
WDYT?

@dunglas
Copy link
Owner

dunglas commented Sep 28, 2023

Good idea! We could update the Docker entrypoint to check if the related packages are installed by doing a grep on composer.json and run the appropriate command if it's the case!

@dunglas
Copy link
Owner

dunglas commented Sep 28, 2023

But the best would probably to update the Flex recipes to run these command automatically when installing these packages thanks to Composer scripts when needed.

@maxhelias
Copy link
Collaborator

The recipe of AssetMapper have the install command : https://github.com/symfony/recipes/blob/main/symfony/asset-mapper/6.4/manifest.json#L13
The same should probably be done for bundles enabling sass or tailwind integration.

Example with the symfony/demo : https://github.com/symfony/demo/blob/main/composer.json#L96-L97

@maxhelias
Copy link
Collaborator

maxhelias commented Feb 15, 2024

@dunglas I think we can simply check if the importmap.php file exists.

I propose to start without any bundle support and see after how we can do.

For a first step, in prod mode, we can add the command php bin/console asset-map:compile in the production stage and in the entrypoint.sh if the statement is true.
And for the dev mode, I'm not sure if we should propose something ? Or let users manage what they want to run ?

@Spomky WDYT ?

@dunglas
Copy link
Owner

dunglas commented Feb 15, 2024

Sounds sensitive to me!

@Spomky
Copy link
Author

Spomky commented Feb 24, 2024

Hi @maxhelias,

It looks good to me too. No need for anything in dev env. I usually run console asset-map:compile --watch directly.

@tviertel
Copy link

tviertel commented May 5, 2024

The assets/ folder is not available in production stage because it is ignored .dockerignore, right?

What I have done is to add these commands to the Makerfile so assets are compiled before building the Docker image:

prod_build: ## Builds Tailwind assets and the Docker images for production environment
	@$(SYMFONY) tailwind:build --minify
	@$(SYMFONY) asset-map:compile
	@$(DOCKER_COMP) -f compose.yaml -f compose.prod.yaml build --pull --no-cache

Maybe another option would be to remove assets/ from .dockerignore, then run the commands at the end of production stage in Dockerfile and delete assets/ after that?

RUN set -eux; \
	mkdir -p var/cache var/log; \
	composer dump-autoload --classmap-authoritative --no-dev; \
	composer dump-env prod; \
	composer run-script --no-dev post-install-cmd; \
	php bin/console tailwind:build --minify; \
	php bin/console asset-map:compile; \
        rm -rf assets/; \
	chmod +x bin/console; sync;

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

No branches or pull requests

4 participants