使用环境标签时NOTYF视图组件不起作用
在我的dotnet 5 MVC
Web应用程序中,我正在使用 this toastnotification
用于显示通知的库。长期以来它运行良好。正如文档所说,它需要_layout
文件中的以下行
@await Component.InvokeAsync("Notyf")
,因此该文件的一部分看起来像:
<script src="~/js/site.js" asp-append-version="true"></script>
<script src="~/js/controls.js" asp-append-version="true"></script>
@await Component.InvokeAsync("Notyf")
@await RenderSectionAsync("Scripts", required: false)
现在我想缩小前两行中提到的js
文件。因此,我为两个文件创建了缩小捆绑包,因此上述部分看起来像:
<environment names="Development">
<script src="~/js/site.js" asp-append-version="true"></script>
<script src="~/js/controls.js" asp-append-version="true"></script>
</environment>
<environment names="Staging,Production">
<script src="~/js/_Bundles/common.min.js" asp-append-version="true"></script>
</environment>
@await Component.InvokeAsync("Notyf")
@await RenderSectionAsync("Scripts", required: false)
更改之后:
- 如果将环境设置为
开发
,则所有这些都像以前一样正常工作。 - 如果我将环境设置为
生产
,则notyf
组件无法正确加载。显然,似乎甚至在可用之前就被使用了。 上收到以下错误
我在加载页面 .png“ alt =”在此处输入图像描述”>
href =“ https://i.sstatic.net/eax8k.png” rel =“ nofollow noreferrer”>
任何想法为什么会发生这种情况?我根本没有碰到这条线。任何解决方案或替代方法都将不胜感激。
In my dotnet 5 MVC
web application, I'm using THIS ToastNotification
library for showing notifications. It's working good since long. As documentation says, it requires following line in _Layout
file
@await Component.InvokeAsync("Notyf")
So a part of this file looks something like:
<script src="~/js/site.js" asp-append-version="true"></script>
<script src="~/js/controls.js" asp-append-version="true"></script>
@await Component.InvokeAsync("Notyf")
@await RenderSectionAsync("Scripts", required: false)
Now I wanted to minify the js
files mentioned in first two lines. So I created minified bundle for the two files, hence the above sections now looks like:
<environment names="Development">
<script src="~/js/site.js" asp-append-version="true"></script>
<script src="~/js/controls.js" asp-append-version="true"></script>
</environment>
<environment names="Staging,Production">
<script src="~/js/_Bundles/common.min.js" asp-append-version="true"></script>
</environment>
@await Component.InvokeAsync("Notyf")
@await RenderSectionAsync("Scripts", required: false)
After this change:
- If I set environment to be
Development
, then all works correctly as before. - If I set environment to be
Production
, theNotyf
component doesn't load correctly. Apparantly it seems like it is being used even before it is available. I get the following error on loading page
Any Idea why is this happening? I did not touch this line at all. Any solution or alternate approach will be appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在非“开发”环境中手动启用
staticwebassetsfileprovider
You need to enable
StaticWebAssetsFileProvider
manually in a not "Development" environment: