简体   繁体   English

Summernote fonts 生产环境不可用

[英]Summernote fonts are unavailable in production environment

I am using Summernote for a page where I want users to be able to format content for news items.我将 Summernote 用于一个页面,我希望用户能够在该页面上设置新闻项目内容的格式。 While the edit panel displays fine in my local development environment, the same edit panel doesn't show the icons when published to my production environment.虽然编辑面板在我的本地开发环境中显示良好,但相同的编辑面板在发布到我的生产环境时不显示图标。 Here is a screenshot:这是一个截图: 在此处输入图像描述

When I inspect the problem page using Edge I notice that some summernote font files are missing, and this obviously makes all kinds of sense:当我使用 Edge 检查问题页面时,我注意到一些 summernote 字体文件丢失了,这显然有各种意义: 在此处输入图像描述

So, clearly, the problem seems to be that the woff, woff2 and ttf files are not available in the expected bundles/font folder that shows in the console error messages.因此,很明显,问题似乎是 woff、woff2 和 ttf 文件在控制台错误消息中显示的预期 bundles/font 文件夹中不可用。 Do I need to make/populate this folder, or redirect summernote to another folder?我是否需要制作/填充此文件夹,或将 summernote 重定向到另一个文件夹?

So, taking a step back, I have a C# .NET Standard 4.8 web project, and I installed summernote using npm which installed the summernote files in my project at node_modules/summernote.所以,退后一步,我有一个 C# .NET Standard 4.8 web 项目,我使用 npm 安装了 summernote,它在我的项目中安装了 summernote 文件,位于 node_modules/summernote。 I can see the font files at node_modules/summernote/dist/font.我可以在 node_modules/summernote/dist/font 看到字体文件。 I have referenced the summernote js and css in my page using bundles, here is a (slightly redacted) code snippet:我在我的页面中使用 bundle 引用了 summernote js 和 css,这里是一个(稍微编辑过的)代码片段:

    bundles.Add(new ScriptBundle("~/bundles/bootstrap").Include(
                    "~/node_modules/summernote/dist/summernote.min.js",
                    "~/node_modules/bootstrap/dist/js/bootstrap.js")
                                .WithLastModifiedToken());

    bundles.Add(new StyleBundle("~/bundles/css").Include(
                    "~/node_modules/bootstrap/dist/css/bootstrap.css",
                    "~/node_modules/summernote/dist/summernote.css")
                                .WithLastModifiedToken());

I did wonder about a different type of bundle for fonts, but I couldn't find anything suitable - this may be the answer if anyone knows how to bundle fonts.我确实想知道 fonts 的不同类型的捆绑包,但我找不到合适的东西 - 如果有人知道如何捆绑 fonts,这可能就是答案。

These then get rendered in the styles and scripts sections of my page template with:这些然后在我的页面模板的 styles 和脚本部分中呈现:

@Styles.Render("~/bundles/css")

and

@Scripts.Render("~/bundles/bootstrap")

Hopefully that all makes sense, happy to provide more info on request.希望一切都有意义,很乐意根据要求提供更多信息。

So far I have tried:到目前为止,我已经尝试过:

  • a post-build event to copy the fonts files into a bundles/font folder in the root of the site.将 fonts 文件复制到站点根目录中的 bundles/font 文件夹中的构建后事件。 This worked in my local development environment (where I was able to download the files by navigating to localhost:XXXX/bundles/fonts, but when I tried this on production it didn't work.这在我的本地开发环境中有效(我可以通过导航到 localhost:XXXX/bundles/fonts 下载文件,但是当我在生产环境中尝试它时它不起作用。
  • I found this question, I couldn't make this work, but I feel the answer may be related to the answer Font files are not loading with ASP.NET Bundles我发现了这个问题,我无法解决这个问题,但我觉得答案可能与答案有关Font files are not loading with ASP.NET Bundles

Any suggestions gratefully received.非常感谢收到任何建议。

I worked out the answer.我想出了答案。

Instead of bundling the css and js into ~/bundles/... I should have been bundling them into ~/Content/..., for example:而不是将 css 和 js 捆绑到 ~/bundles/... 我应该将它们捆绑到 ~/Content/...,例如:

bundles.Add(new ScriptBundle("~/Content/summernote").<etc>
bundles.Add(new StyleBundle("~/Content/summernote-css").<etc>

This allowed me to get to a solution by making a new /font/ folder in the Content folder in my MVC project just where the "~/Content/summernote" bundles expected to find them.这使我能够通过在我的 MVC 项目的 Content 文件夹中创建一个新的 /font/ 文件夹来找到解决方案,就在“~/Content/summernote”包期望找到它们的地方。

The key was that the css and js bundles were bundling stuff into ~/bundles/bootstrap, and when I looked at the summernote code it was referencing the fonts using a relative URL. It didn't occur to me that I could bundle the js and css anywhere except ~/bundles/... until I was walking in the woods this weekend.关键是 css 和 js 捆绑包将东西捆绑到 ~/bundles/bootstrap 中,当我查看 summernote 代码时,它使用相对 URL 引用 fonts。我没想到我可以捆绑 js和 css 除了 ~/bundles/... 的任何地方,直到这个周末我在树林里散步。 Fixed in 5 minutes. 5 分钟内修复。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM