-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webassets;doc update;ignoring files fix.
- Loading branch information
1 parent
6548f84
commit 0386232
Showing
12 changed files
with
185 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
@page "/docs/componentlibs" | ||
@using Microsoft.FluentUI.AspNetCore.Components | ||
|
||
<div class="prose prose-invert"> | ||
<h1>Fluent UI (and Other Component Libraries) with BlazorStatic</h1> | ||
<p> | ||
You can use FluentUI with BlazorStatic, as long as you understand its limitations. | ||
</p> | ||
|
||
<p> | ||
Only the interactivity handled by JavaScript will work. | ||
</p> | ||
<p> | ||
BlazorStatic will copy all necessary files to the output folder, as expected upon app publish. | ||
</p> | ||
<p> | ||
BlazorStatic is based on Blazor Server-Side Rendering (SSR). For FluentUI to work with SSR, reference the necessary JavaScript as described in the <a href="https://github.com/microsoft/fluentui-blazor?tab=readme-ov-file#script">FluentUI documentation</a>. | ||
</p> | ||
<p> | ||
This information is not tied exclusively to FluentUI; it allows you to use any Blazor component library. | ||
</p> | ||
|
||
</div> | ||
|
||
<div class="prose prose-invert"> | ||
|
||
<h2 class="prose prose-invert"> Example using some FluentUI components</h2> | ||
</div> | ||
|
||
<FluentButton Appearance="@Appearance.Accent">Button</FluentButton> | ||
<FluentBadge>Badge</FluentBadge> | ||
|
||
<FluentSelect Value=@("a string value") TOption="string"> | ||
<FluentOption>Option1</FluentOption> | ||
<FluentOption>Option2</FluentOption> | ||
<FluentOption>Option3</FluentOption> | ||
</FluentSelect> | ||
|
||
|
||
<script src="_content/Microsoft.FluentUI.AspNetCore.Components/Microsoft.FluentUI.AspNetCore.Components.lib.module.js" type="module" async></script> | ||
@code { | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
--- | ||
title: Release of 1.0.0-beta.4 | ||
lead: Static web assets are always copied. The IsDraft property in the default FrontMatter is now supported. | ||
published: 2024-01-20 | ||
tags: [release] | ||
authors: | ||
- name: "Jan Tesař" | ||
gitHubUserName: "tesar-tech" | ||
twitterUserName: "tesar-tech" | ||
--- | ||
|
||
## Breaking change: | ||
|
||
- Use `builder.WebHost.UseStaticWebAssets();` to ensure static assets are copied to the output folder. See [One little catch](#one-little-catch-with-one-liner-solution) for more info. | ||
|
||
## Static web assets are always copied | ||
|
||
**tl;dr**: It works as expected, just add `builder.WebHost.UseStaticWebAssets();` to your `Program.cs`. | ||
|
||
Previously, it wasn't possible to copy static web assets from a Razor class library to the output folder. These assets, residing in the NuGet cache, are served by the framework. Static web assets from RCLs (e.g., CSS files or images) are accessed through the `_content/` path and are copied to the `wwwroot` folder upon publishing. However, BlazorStatic is designed to output the entire website, even during development (without publishing). An addition was made to copy the static web assets from RLCs using `app.Environment.WebRootFileProvider`. | ||
|
||
Now, you can use any NuGet package with static web assets (for example, FluentUI; [check how it runs with BlazorStatic](/docs/componentlibs)), and it will work as expected. | ||
|
||
This also addresses the lack of support for scoped CSS in BlazorStatic. Use scoped CSS as you normally would. | ||
|
||
### One little catch (with one-liner solution) | ||
BlazorStatic now relies on `app.Environment.WebRootFileProvider` to copy static web assets. You need to enable `StaticWebAssets`. In non-dev environments (Staging, Production, etc.), `StaticWebAssets` are turned off. The issue is described [here](https://dev.to/j_sakamoto/how-to-deal-with-the-http-404-content-foo-bar-css-not-found-when-using-razor-component-package-on-asp-net-core-blazor-app-aai) (with older .NET, but the principle is the same): | ||
|
||
See it in the `WebHost.cs` file in the [aspnetcore repo](https://github.com/dotnet/aspnetcore/blob/cc9cff31eb828f5849c07afc46b08baeda42b399/src/DefaultBuilder/src/WebHost.cs#L221): | ||
|
||
This becomes a problem when switching the `ASPNETCORE_ENVIRONMENT` to anything other than Development, which I recommend doing in GitHub Actions workflows (or similar). | ||
|
||
The problem results in missing static web assets (CSS, images, etc.) in the output folder. | ||
|
||
How to prevent this? Easily by activating `StaticWebAssets` in your `Program.cs`: | ||
|
||
```csharp | ||
var builder = WebApplication.CreateBuilder(args); | ||
|
||
builder.WebHost.UseStaticWebAssets(); //👈 | ||
``` | ||
You might wonder: "Aren't StaticWebAssets turned off in prod for a reason?" | ||
|
||
Yes, but: (simply put) for apps that run on a server. | ||
|
||
A web app using BlazorStatic is meant for quick static website generation, not server deployment. | ||
|
||
If you need to disable `StaticWebAssets`, consider this workaround: | ||
|
||
- Add the `wwwroot` folder to `opt.ContentToCopyToOutput`. | ||
- Publish the app before running. | ||
|
||
I haven't tested this; let me know if you need it. I am curious about the use case. | ||
|
||
## IsDraft property in default FrontMatter is now supported | ||
|
||
First merged PR from community! Thanks to [Chris Gonzales](https://github.com/chrisg32) for this contribution. | ||
|
||
Default `FrontMatter` has now support for `IsDraft` property. | ||
If you set it to `true` the page will be ignored during generation. A useful feature indeed. | ||
|
||
Note: You don't have to use the default FrontMatter at all. | ||
You can tailor the front matter class based on your markdown posts' structure. | ||
|
||
## Ignoring files for the generation works | ||
|
||
To ignore certain files, configure it in `Program.cs`: | ||
|
||
```csharp | ||
builder.Services.AddBlazorStaticService(opt => { | ||
opt.IgnoredPathsOnContentCopy.AddRange(new[] { "app.css" }); | ||
}); | ||
``` | ||
|
||
For example, I ignore the `app.css` file used by TailwindCSS to create the final CSS version (`app.min.css`). | ||
There's no need to keep `app.css` in the output. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters