[英]ASP.NET Core MVC 2.1 View Compilation on Publish to Azure
I created a class that inherits from RazorProjectFileSystem that performs minification on cshtml files prior to them being compiled.我创建了一个继承自 RazorProjectFileSystem 的 class,它在编译 cshtml 文件之前对其执行缩小。 This is configured in
Startup.ConfigureServices
.这是在
Startup.ConfigureServices
中配置的。
Works just fine when running locally, stripping out a mass of whitespace and comments.在本地运行时工作得很好,去掉了大量的空白和注释。 However when the site is published to Azure a
ProjectName.Views.dll
is created, which completely bypasses my logic.但是,当站点发布到 Azure 时,会创建一个
ProjectName.Views.dll
,这完全绕过了我的逻辑。
I still want to use precompiled views (and yes, we are using gzip compression as well), but will need to plug my logic somewhere else in the chain to get this to happen.我仍然想使用预编译的视图(是的,我们也在使用 gzip 压缩),但是需要将我的逻辑插入到链中的其他位置才能实现。 However I can't find any information on where the.cshtml files are read from the file system as part of the creation of the View.dll.
但是,作为创建 View.dll 的一部分,我找不到任何关于从文件系统中读取 .cshtml 文件的位置的任何信息。
I suspect we may need to run the minification prior to the actual build process itself.我怀疑我们可能需要在实际构建过程本身之前运行缩小。 Any ideas or recommendations very much appreciated.
非常感谢任何想法或建议。
There are many libraries available to do build time minification of CSHTML files, you can use **gulp-cshtml-minify**
.有许多库可用于缩小 CSHTML 文件的构建时间,您可以使用
**gulp-cshtml-minify**
。 Only problem with this one is that you have to install node and gulp for using this.唯一的问题是您必须安装节点和 gulp 才能使用它。
Here is a detailed elaboration on this.这是对此的详细阐述。 which you can find it in below blog:
您可以在下面的博客中找到它:
https://debugandrelease.blogspot.com/2018/11/automatically-minifying-cshtml-files-in.html https://debugandrelease.blogspot.com/2018/11/automatically-minifying-cshtml-files-in.html
Only thing which you have to do is append.min word while pulling the vies from the folder like below:您唯一需要做的就是 append.min 字,同时从如下文件夹中拉出 vies:
public override ViewResult View(string viewName, object model)
{
if (!IsDevelopment())
{
string action = ControllerContext.RouteData.Values["action"].ToString();
if (string.IsNullOrEmpty(viewName))
{
viewName = $"{action}.min";
}
else if (viewName == action)
{
viewName += ".min";
}
}
return base.View(viewName, model);
}
Hope it helps.希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.