Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,16 @@ Or else, if you are using tailwindcss v3, then:
@tailwind utilities
```

If you are using any local dependencies you will need to use absolute paths.
For example,
```css
@import "./daisyui.js";
```
becomes;
```@css
@import "/home/user/jaspr_project/web/daisyui.js"
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like the solution to use absolute paths. That makes it impossible to use it in a team, especially if everyone uses a different OS. And even without a team I'd prefer not to check in anything absolute.

Do you really need to use a scratchspace (as that seems to be the problem)? Can't you generate the css file in place? For example sass_builder works without any scatch spaces to create its css files (https://github.com/dart-league/sass_builder/blob/master/lib/sass_builder.dart).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dazemc @dinko7
If the sole reason for using a scratchspace is that the file created by tailwindcss would conflict with the build process, you can remove the --output parameter and the output will be written to stdout and you could do something like:

  final process = await Process.run(
    'tailwindcss',
    ...
  );

  final cssFileContent = process.stdout;

Then write that file like you normally would in a build. Additionally process.stderr contains the message about success/failure of the invocation of tailwindcss.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really a solution I know. I think that using scratch space is a recommendation for build runner but I'm not entirely sure why it's being used other than maybe to ensure file permissions and a consistent clean state, I'm not sure if this is related to Jaspr's hot reload. If scratch space is a requirement, I had a suggestion to add an import directory for relative imports that would just get symlinked to the scratch space.
I did add a change to check the output of stderr in this PR too.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I did that change with removing the output parameter and it works for me. I can use daisyui with relative paths.

Feel free to use these changes for your pull request if you want to: https://github.com/denniskaselow/jaspr_tailwind

(changed build_to to source so the final css is still created in the web folder, but it would still work with cache)

```

Finally, link the generated `styles.css` in your document, or otherwise add it to your website:

In **static** or **server** mode:
Expand Down
24 changes: 19 additions & 5 deletions lib/builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ class TailwindBuilder implements Builder {

await scratchSpace.ensureAssets({buildStep.inputId}, buildStep);

var outputId = buildStep.inputId.changeExtension('').changeExtension('.css');
var outputId =
buildStep.inputId.changeExtension('').changeExtension('.css');

var packageFile = File('.dart_tool/package_config.json');
var packageJson = jsonDecode(await packageFile.readAsString());

var packageConfig = (packageJson['packages'] as List?)?.where((p) => p['name'] == 'jaspr_tailwind').firstOrNull;
var packageConfig = (packageJson['packages'] as List?)
?.where((p) => p['name'] == 'jaspr_tailwind')
.firstOrNull;
if (packageConfig == null) {
print("Cannot find 'jaspr_tailwind' in package config.");
return;
Expand All @@ -37,25 +40,36 @@ class TailwindBuilder implements Builder {
var configFile = File('tailwind.config.js');
var hasCustomConfig = await configFile.exists();

await Process.run(
final runTailwind = await Process.run(
'tailwindcss',
[
'--input',
scratchSpace.fileFor(buildStep.inputId).path,
'--output',
scratchSpace.fileFor(outputId).path.toPosix(),
if (options.config.containsKey('tailwindcss')) options.config['tailwindcss'],
if (options.config.containsKey('tailwindcss'))
options.config['tailwindcss'],
if (hasCustomConfig) ...[
'--config',
p.join(Directory.current.path, 'tailwind.config.js').toPosix(),
] else ...[
'--content',
p.join(Directory.current.path, '{lib,web}', '**', '*.dart').toPosix(true),
p
.join(Directory.current.path, '{lib,web}', '**', '*.dart')
.toPosix(true),
],
],
runInShell: true,
);

final stderrLines = runTailwind.stderr.toString().trim().split('\n');
final lastLine = stderrLines.isNotEmpty ? stderrLines.last : '';
if (lastLine.contains('Done')) {
log.info(runTailwind.stderr);
} else {
log.severe(runTailwind.stderr);
}

await scratchSpace.copyOutput(outputId, buildStep);
}

Expand Down