paultechguy
paultechguy

Reputation: 2518

Publish only minified versions of JavaScript files (ASPNET Core)

Although there are several articles on this issue, I can't seem to find any that are recent and apply to ASPNET Core 2.x, Visual Studio 2017.

How do I only publish my minified versions of JavaScript (.js) files?

It would be nice to do this via the publish profile (.pubxml) so that I can include/exclude by setting up different publish profiles (Dev, UAT, Staging, Production.

Upvotes: 4

Views: 2301

Answers (2)

Retro
Retro

Reputation: 86

Just exclude all .css/.js files and then include .min files. The last rule overrides the previous.

<ItemGroup>
   <Content Update="wwwroot\**\*.css" CopyToPublishDirectory="never" />
   <Content Update="wwwroot\**\*.min.css" CopyToPublishDirectory="always" />
   <Content Update="wwwroot\**\*.js" CopyToPublishDirectory="never" />
   <Content Update="wwwroot\**\*.min.js" CopyToPublishDirectory="always" />
</ItemGroup>

Upvotes: 7

DeProgrammer
DeProgrammer

Reputation: 1

Publish profiles are essentially project file overrides and use the same schema as project files. Microsoft supplies an example here: https://learn.microsoft.com/en-us/aspnet/core/host-and-deploy/visual-studio-publish-profiles?view=aspnetcore-2.2#exclude-files

<ItemGroup>
  <Content Update="wwwroot/content/**/*.txt" CopyToPublishDirectory="Never" />
</ItemGroup>

Additionally, you can set any file in your project to be included or excluded based on build configuration directly in the project: Conditional Content Based Upon Configuration

Upvotes: 0

Related Questions