admin管理员组文章数量:1431726
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.
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.
Share Improve this question edited Feb 27, 2019 at 15:25 Heretic Monkey 12.1k7 gold badges61 silver badges131 bronze badges asked Feb 27, 2019 at 15:13 paultechguypaultechguy 2,5385 gold badges27 silver badges38 bronze badges 5- there is MVc bundle, wont this work for you ? – Alen.Toma Commented Feb 27, 2019 at 15:21
- 1 If you are referring to creating a bundle of minified files, that doesn't solve the original .js file from being published...where anyone can view it by adjusting the URL. – paultechguy Commented Feb 27, 2019 at 18:34
- I mean you could have two diffrent bundles, one On release and other on debugg, the same could also be applied with diffrent attr to. have a look at this, not sure if this is the answer your looking for though.stackoverflow./questions/3788605/… – Alen.Toma Commented Feb 27, 2019 at 18:47
- Sure, I can create two bundles, but it just seems so hacky. I just don't know why you can't have something in your publish config that would help say, don't deploy these files. That is my question. – paultechguy Commented Feb 28, 2019 at 23:48
- This just doesn't appear possible, so I wrote a post build powershell that just deletes CSS and JavaScript files where a minified version exists. – paultechguy Commented Apr 20, 2019 at 0:56
2 Answers
Reset to default 7Just 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>
Publish profiles are essentially project file overrides and use the same schema as project files. Microsoft supplies an example here: https://learn.microsoft./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
本文标签: Publish only minified versions of JavaScript files (ASPNET Core)Stack Overflow
版权声明:本文标题:Publish only minified versions of JavaScript files (ASPNET Core) - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745563145a2663594.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论