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

Windows Docker and Tailwind watch mode #57

Merged
merged 4 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ That's it! This will watch for changes to your ``assets/styles/app.css`` file
and automatically recompile it when needed. If you refresh the page, the
final ``app.css`` file will already contain the compiled CSS.

Watch mode in Docker with Windows host
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

If you work on Windows and your app is running in a Docker container, and you
are having trouble with the ``--watch`` option, you can try runnig the ``tailwind:build``
command with ``--poll-watch`` option.

.. code-block:: terminal

$ php bin/console tailwind:build --poll-watch

Symfony CLI
~~~~~~~~~~~

Expand Down
2 changes: 2 additions & 0 deletions src/Command/TailwindBuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ protected function configure(): void
{
$this
->addOption('watch', 'w', null, 'Watch for changes and rebuild automatically')
->addOption('poll-watch', null, null, 'Watch for changes and rebuild automatically (with --poll flag)')
->addOption('minify', 'm', InputOption::VALUE_NONE, 'Minify the output CSS')
;
}
Expand All @@ -44,6 +45,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$process = $this->tailwindBuilder->runBuild(
watch: $input->getOption('watch'),
pollWatch: $input->getOption('poll-watch'),
minify: $input->getOption('minify'),
);
$process->wait(function ($type, $buffer) use ($io) {
Expand Down
6 changes: 5 additions & 1 deletion src/TailwindBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,22 @@ public function __construct(

public function runBuild(
bool $watch,
bool $pollWatch,
bool $minify,
): Process {
$binary = $this->createBinary();
$arguments = ['-c', $this->configPath, '-i', $this->inputPath, '-o', $this->getInternalOutputCssPath()];
if ($watch) {
$arguments[] = '--watch';
} elseif ($pollWatch) {
$arguments[] = '--watch';
$arguments[] = '--poll';
}
if ($minify) {
$arguments[] = '--minify';
}
$process = $binary->createProcess($arguments);
if ($watch) {
if ($watch || $pollWatch) {
$process->setTimeout(null);
// setting an input stream causes the command to "wait" for the watch
$inputStream = new InputStream();
Expand Down
4 changes: 2 additions & 2 deletions tests/TailwindBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function testIntegrationWithDefaultOptions(): void
null,
__DIR__.'/fixtures/tailwind.config.js'
);
$process = $builder->runBuild(watch: false, minify: false);
$process = $builder->runBuild(watch: false, pollWatch: false, minify: false);
$process->wait();

$this->assertTrue($process->isSuccessful());
Expand All @@ -67,7 +67,7 @@ public function testIntegrationWithMinify(): void
null,
__DIR__.'/fixtures/tailwind.config.js'
);
$process = $builder->runBuild(watch: false, minify: true);
$process = $builder->runBuild(watch: false, pollWatch: false, minify: true);
$process->wait();

$this->assertTrue($process->isSuccessful());
Expand Down
Loading