Reputation: 20699
Razor Pages has a bundling feature for use with css isolation.
I have these pages:
/Pages/Products/Index.cshtml.css
/Pages/Orders/Edit.cshtml.css
/Pages/Orders/Create.cshtml.css
During compilation, a bundle will be generated: ~/AssemblyName.styles.css
.
However, suppose I also have private pages only for staff members:
/Pages/Private/Accounts.cshtml.css
/Pages/Private/Administration.cshtml.css
/Pages/Private/Dashboard.cshtml.css
They would be included in the same bundle as above.
How can I generate two bundles: one for users, and another for staff?
UPDATE
I'm aware of tools for compiling / minifying / bundling, but prefer a built-in approach if possible.
Upvotes: 1
Views: 334
Reputation: 20699
The simple answer is this is not currently possible.
The other answer shows a workaround using a separate tool (WebOptimizer). It is not actively maintained, so beware (see the repo's issues to understand the problem). There are other tools as well, such as Smidge. All such tools are out of date, or maintained by just one core contributor - I think that's too risky for a production system.
What I'm doing currently is manually concatenating the files as an msbuild task.
Upvotes: 0
Reputation: 9112
ASP.NET Core is compatible with WebOptimizer, an open-source bundling and minification solution. For set up instructions and sample projects, see WebOptimizer. ASP.NET Core doesn't provide a native bundling and minification solution.
Bundling is the process of taking multiple source files and combining them into a single output file. We can create one for users. like:
builder.Services.AddWebOptimizer(pipeline =>
{
pipeline.AddCssBundle("/css/bundle.css", "css/a.css", "css/b.css");
});
When using bundling, we have to update our and tags to point to the bundle route. It could look like this:
<link rel="stylesheet" href="/css/bundle.css" />
You can have a look at Bundle and minify static assets in ASP.NET Core and Bundling to know more.
Upvotes: 1