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

How to bundle static assets from multiple razor library packages #14726

Closed
ToddThomson opened this issue Oct 4, 2019 · 12 comments
Closed

How to bundle static assets from multiple razor library packages #14726

ToddThomson opened this issue Oct 4, 2019 · 12 comments
Assignees
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates question
Milestone

Comments

@ToddThomson
Copy link

Is there an AspNetCore built-in design for this?

@mkArtakMSFT mkArtakMSFT added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates question labels Oct 4, 2019
@mkArtakMSFT
Copy link
Member

Thanks for contacting us, @ToddThomson.
It's not clear exactly what you're asking for. You can read about static assets at https://docs.microsoft.com/en-us/aspnet/core/razor-pages/ui-class?view=aspnetcore-3.0&tabs=visual-studio#create-an-rcl-with-static-assets.
If the docs don't have an answer to your question, please try to provide more details about what your'e trying to achieve and reopen this issue.

@ToddThomson
Copy link
Author

Sorry, my post was a bit terse!

I am clear on how to package static assets within a RCL. However, if I have AspNetCore 3 Web project that consumes multiple RCLs, is there a mechanism to bundle assets from these multiple RCLs? I would be interested in development time and production time scenarios. Issue #6349 mentions different bundling scenarios, but I am not clear if the design(s) were implemented.

@ToddThomson
Copy link
Author

I took a look at Microsoft.NET.Sdk.Razor.StaticWebAssets.targets and there does appear to be a mechanism to determine static assets resolved from packages and included projects. Is there any guidance on how to utilize this to perform bundling?

@ToddThomson
Copy link
Author

ToddThomson commented Oct 4, 2019

@mkArtakMSFT please consider reopening this issue. It appears that I cannot reopen this issue myself.

@ToddThomson
Copy link
Author

Perhaps AspNetCore Tooling Tests will provide some insights...

@mkArtakMSFT mkArtakMSFT reopened this Oct 4, 2019
@mkArtakMSFT
Copy link
Member

I'm a bit uncertain about what bundling aspect of this. All the content from each reference RCL project 's wwwroot folder will be available to the consuming web application. The Multi-project development flow section in the docs talks about this: https://docs.microsoft.com/en-us/aspnet/core/razor-pages/ui-class?view=aspnetcore-3.0&tabs=visual-studio#multi-project-development-flow

@ToddThomson
Copy link
Author

ToddThomson commented Oct 4, 2019

@mkArtakMSFT Thanks Artak. I have a few leads to go on now. If I can access the aggregated staticwebassets build directory post build I may be able to construct bundles during development.

I am not sure how using the aspnetcore bundle and minifier would work at runtime. Any guidance would be time saving and helpful!

Edit: I will look at the doc you linked to above...

@ToddThomson
Copy link
Author

ToddThomson commented Oct 4, 2019

@mkArtakMSFT OK, it is the publish step where all the publish/wwwroot/_content/libRCL/ directories are created that I want to get access to from my consuming MVC Web project. I should be able to use the runtime aspnetcore bundler or a gulp based bundler to reference the _content/ directory.

What I am attempting to do is compose single js and css bundles from a set of included RCL packages or included projects. I feel the answer is in the access to the _content\ build directory. I will write a bit of code to test this out.

@ToddThomson
Copy link
Author

ToddThomson commented Oct 4, 2019

Ok. So the MS AspNetCore project does not include a built-in bundler/minifier for static assets. I assumed that the NuGet package, that used bundleconfig.json was from Microsoft (I am migrating to AspNetCore 3 from AspNetCore 2). That's OK with me as I have always used gulp tasks.

So my question comes down to this:

When publishing the MVC Web App that consumes multiple RCL packages, a publish\wwwroot\_content\**\* directory is create with each RCL's static assets being added as subdirectories. Is this wwwroot\_content\**\* directory resource somehow available to post build gulp tasks?

@mkArtakMSFT
Copy link
Member

@javiercn I will need your expertise here. Can you please see whether this is possible and how (if yes)?

@javiercn
Copy link
Member

javiercn commented Oct 7, 2019

@ToddThomson We don't offer a solution for this out of the box, but all the infrastructure is done through MSBuild and there are extensibility points that should make this scenarios possible.

In particular, you should be able to add your own targets to get the list of all the assets in the app, run any code you want, and produce an updated list of assets that the app will use.

For example, you can add your own task to ResolveStaticWebAssetsInputsDependsOn on your web app project to:

  • Get a list of all the assets you are interested on.
  • Invoke your favorite bundler/minifier tools to create the bundles.
  • Update the list of static web assets to reflect the updated list of assets.

@ToddThomson
Copy link
Author

@javiercn Thank-you. I've looked at the Razor Sdk StaticWebAssets.targets tasks and will likely use:

<Target
    Name="_StaticWebAssetsComputeFilesToPublish"
    AfterTargets="ComputeResolvedFilesToPublishList"
    DependsOnTargets="ResolveStaticWebAssetsInputs">

as a guide for my target.

@mkArtakMSFT mkArtakMSFT added this to the Discussions milestone Oct 7, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates question
Projects
None yet
Development

No branches or pull requests

3 participants