@Scripts.Render()当我没有捆绑脚本时,我的网站在localhost上正常工作,但是当我部署到我的服务器时,捆绑的Javascript必须包含错误,因为我页面上的所有Javascript都停止工作.
这是我的捆绑代码:
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js",
"~/Scripts/jquery-migrate-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui-{version}.js",
"~/Scripts/jquery-ui.unobtrusive-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/modernizr").Include(
"~/Scripts/modernizr-*"));
bundles.Add(new StyleBundle("~/Content/css").Include("~/Content/site.css"));
bundles.Add(new StyleBundle("~/Content/themes/base/css").Include(
"~/Content/themes/base/jquery.ui.core.css",
"~/Content/themes/base/jquery.ui.resizable.css",
"~/Content/themes/base/jquery.ui.selectable.css",
"~/Content/themes/base/jquery.ui.accordion.css",
"~/Content/themes/base/jquery.ui.autocomplete.css",
"~/Content/themes/base/jquery.ui.button.css",
"~/Content/themes/base/jquery.ui.dialog.css",
"~/Content/themes/base/jquery.ui.slider.css",
"~/Content/themes/base/jquery.ui.tabs.css",
"~/Content/themes/base/jquery.ui.datepicker.css",
"~/Content/themes/base/jquery.ui.progressbar.css",
"~/Content/themes/base/jquery.ui.theme.css"));
}
Run Code Online (Sandbox Code Playgroud)
这是我的渲染代码:
@Styles.Render("~/Content/css")
@Styles.Render("~/Content/themes/base/css")
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/jqueryval")
@Scripts.Render("~/bundles/jqueryui")
@Scripts.Render("~/bundles/modernizr")
Run Code Online (Sandbox Code Playgroud)
有人可以解释部署时我的Javascript可能会发生什么吗?
谢谢,亚历克斯.
我有一个项目,当你从visual studio中运行时,它可以与捆绑一起使用.但是,在进行部署之后,捆绑处理程序似乎永远不会选择路由.它最终转到静态文件处理程序,返回404响应.
有任何想法吗?我在IIS下的网站bin中看到了优化程序集.
它使用4.0应用程序池和集成模式.
我想知道是否有人有任何想法或建议?
谢谢
-----根据问题更新-----
VS2012
targetFramework = "4.5"
我还在视图中添加了一些代码,以显示哪些模块已加载,我可以看到其中列出的bundle模块.
BundleConfig是使用Internet Application MVC4项目模板时提供的默认值.
该站点正在部署到根目录中.奇怪的是,当我设置EnableOptimizations = true时(由于通过visual studio F5在调试模式下运行),它完美无缺!我可以导航到content/css,它会吐出组合的CSS.
我部署它,其他一切工作,但捆绑!
我不想缩小我在ASP .NET MVC 4解决方案中使用的所有文件.例如,我在BundleConfig.cs中有这个:
bundles.Add(new StyleBundle("~/CSS/bootstrap").Include(
"~/Content/Bootstrap/body.css",
"~/Content/Bootstrap/bootstrap-responsive.css",
"~/Content/Bootstrap/bootstrap-mvc-validation.css",
"~/Content/Bootstrap/bootstrap-theme.css",
"~/Content/Bootstrap/bootstrap.css"
));
...
Run Code Online (Sandbox Code Playgroud)
为了缩小它,我当然使用:
BundleTable.EnableOptimizations = true;
Run Code Online (Sandbox Code Playgroud)
所以它很棒.
但是现在,除了一个捆绑包之外,我怎么能缩小我的所有文件?我有一个捆绑的问题,删除了一些CSS类,并希望不缩小这一个.
任何帮助将不胜感激.
我知道他们都把宝石放在你的应用程序的不同位置,但似乎捆绑安装 - 部署做得更彻底.我可以将它创建的供应商/包目录添加到版本控制并完成吗?
我跑了bundle install vendor/gems,所有的宝石都按预期保存到了gems目录,但当我删除它们时
rm -rf vendor/gems
rails s
Could not find rake-0.9.2.2 in any of the sources
Run `bundle install` to install missing gems.
Run Code Online (Sandbox Code Playgroud)
我需要再次运行bundle install,所有的gem vendor/gems再次安装.有没有办法让这种行为停止,只是安装,因为我以前使用我的.rvmrc文件,而不是将gem包装在vendor/gems目录中
我想知道是否有人可以帮助我使用MVC 4附带的新优化命名空间进行捆绑和缩小.我有一个Multitenant应用程序,我想根据每个用户的设置决定应该加载哪些js文件.一种方法是预先创建所有捆绑包并根据用户的设置更改resolvebundleurl的虚拟路径,但这感觉不是真正正确的方式.另外,我在基于用户设置的cshtml视图中有动态css,我想在运行时缩小它.
有什么建议?在其他问题中我也看到很多反应来检查Requestreduce,但它们都来自同一个用户.
处理这两种情况的最佳方法是什么?
提前致谢!
asp.net optimization bundle asp.net-mvc-4 asp.net-optimization
如果缺少javascript或css文件,是否可能以某种方式抛出异常?
我已尝试使用下面的代码,但它从未抛出异常......
public class BundleConfig {
public static void RegisterBundles(BundleCollection bundles) {
....
bundles.Add(new ScriptBundle("~/bundles/something").Include("~/Scripts/nonExistingFile.js"));
// I would like the above usage of Include method with
// a non-existing file to throw an exception to make it
// obvious that an expected file is missing ...
// but since it does not I tried to implement a method as below ...
...
AssertThatAllFilesExist(bundles);
// but unfortunately an exception is never thrown but when
// iterating the files in the method …Run Code Online (Sandbox Code Playgroud) 有一个images.xcassets在我的项目,它包含一个icons文件夹,两个子文件夹(firstFolder,secondFolder)与图像.我的两个子文件夹都有相同数量的图标和相同的图标名称(针对我的应用程序的不同主题).
所以我正在寻找:我需要从我的包中获取所需的图标(当前主题).
我试过这样的事情:
NSBundle* bundle = [NSBundle bundleForClass:[self class]];
NSString *imageName = [bundle.bundlePath stringByAppendingPathComponent:@"icons/firstFolder/neededIcon"];
Run Code Online (Sandbox Code Playgroud)
这是行不通的.
我正在研究iOS的框架,它带有一些数据文件.要将它们加载到Dictionary我做这样的事情:
public func loadPListFromBundle(filename: String, type: String) -> [String : AnyObject]? {
guard
let bundle = Bundle(for: "com.myframework")
let path = bundle.main.path(forResource: filename, ofType: type),
let plistDict = NSDictionary(contentsOfFile: path) as? [String : AnyObject]
else {
print("plist not found")
return nil
}
return plistDict
}
Run Code Online (Sandbox Code Playgroud)
如果我在带有框架的游乐场中使用它,它可以按预期工作.
但是,如果我使用嵌入在应用程序中的框架,它不再起作用,"路径"现在指向应用程序的捆绑,而不是框架.
如何确保访问框架的捆绑包?
编辑:上面的代码驻留在框架中,而不是在应用程序中.
EDIT2:上面的代码是一个实用函数,不是结构或类的一部分.
尝试mimemagic 0.3.10在 Ruby on Rails 项目中安装时遇到以下错误。注意,它是在Windows环境下运行的。这是最相关的错误堆栈跟踪:
Fetching mimemagic 0.3.10
Installing mimemagic 0.3.10 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory:
C:/Ruby26/lib/ruby/gems/2.6.0/gems/mimemagic-0.3.10/ext/mimemagic
C:/Ruby26/bin/ruby.exe -rrubygems
C:/Ruby26/lib/ruby/gems/2.6.0/gems/rake-13.0.6/exe/rake
RUBYARCHDIR\=C:/Ruby26/lib/ruby/gems/2.6.0/extensions/x86-mingw32/2.6.0/mimemagic-0.3.10
RUBYLIBDIR\=C:/Ruby26/lib/ruby/gems/2.6.0/extensions/x86-mingw32/2.6.0/mimemagic-0.3.10
rake aborted!
Could not find MIME type database in the following locations:
["/usr/local/share/mime/packages/freedesktop.org.xml",
"/opt/homebrew/share/mime/packages/freedesktop.org.xml",
"/opt/local/share/mime/packages/freedesktop.org.xml",
"/usr/share/mime/packages/freedesktop.org.xml"]
Ensure you have either installed the shared-mime-info package for your
distribution, or
obtain a version of freedesktop.org.xml and set FREEDESKTOP_MIME_TYPES_PATH to
the location
of that file.
This gem might be installed …Run Code Online (Sandbox Code Playgroud) bundle ×10
asp.net-mvc ×2
bundler ×2
c# ×2
ios ×2
asp.net ×1
assets ×1
frameworks ×1
gem ×1
javascript ×1
mime ×1
objective-c ×1
optimization ×1
razor-2 ×1
ruby ×1
rubygems ×1
rvm ×1
swift ×1
swift3 ×1
xcode ×1