Last active
August 29, 2015 14:13
-
-
Save stimms/729d125d50e09e9e1dd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bundles.Add(new PreassembledJavaScriptBundle("~/Scripts/all.min.js", "~/bundles/site") | |
.IncludeDirectory("~/Scripts/Site", "*.js", true)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class PreassembledJavaScriptBundle : Bundle | |
{ | |
private string _virtualPathToPreassembedFile { get; set; } | |
protected PreassembledJavaScriptBundle(string virtualPathToPreassembedFile) | |
{ | |
SetupvirtualPathToPreassembedFile(virtualPathToPreassembedFile); | |
} | |
public PreassembledJavaScriptBundle(string virtualPathToPreassembedFile, string virtualPath, string cdnPath, params IBundleTransform[] transforms) | |
: base(virtualPath, cdnPath, transforms) | |
{ | |
SetupvirtualPathToPreassembedFile(virtualPathToPreassembedFile); | |
} | |
public PreassembledJavaScriptBundle(string virtualPathToPreassembedFile, string virtualPath, params IBundleTransform[] transforms) | |
: this(virtualPathToPreassembedFile, virtualPath, null, transforms) | |
{ | |
} | |
public PreassembledJavaScriptBundle(string virtualPathToPreassembedFile, string virtualPath) | |
: this(virtualPathToPreassembedFile, virtualPath, (string)null, null) | |
{ | |
} | |
public PreassembledJavaScriptBundle(string virtualPathToPreassembedFile, string virtualPath, string cdnPath) | |
: this(virtualPathToPreassembedFile, virtualPath, cdnPath, null) | |
{ | |
} | |
public override BundleResponse GenerateBundleResponse(BundleContext context) | |
{ | |
IEnumerable<BundleFile> bundleFiles = EnumerateFiles(context); | |
bundleFiles = context.BundleCollection.IgnoreList.FilterIgnoredFiles(context, bundleFiles); | |
bundleFiles = Orderer.OrderFiles(context, bundleFiles); | |
if (EnableFileExtensionReplacements) | |
{ | |
bundleFiles = context.BundleCollection.FileExtensionReplacementList.ReplaceFileExtensions(context, bundleFiles); | |
} | |
string fileContents; | |
using (var reader = new StreamReader(BundleTable.VirtualPathProvider.GetFile(_virtualPathToPreassembedFile).Open())) | |
{ | |
fileContents = reader.ReadToEnd(); | |
} | |
var response = new BundleResponse(fileContents, bundleFiles); | |
response.ContentType = "text/javascript"; | |
return response; | |
} | |
private void SetupvirtualPathToPreassembedFile(string virtualPathToPreassembedFile) | |
{ | |
if (!BundleTable.VirtualPathProvider.FileExists(virtualPathToPreassembedFile)) | |
throw new FileNotFoundException(String.Format("Unable to load preassembed bundle file: {0}", virtualPathToPreassembedFile)); | |
_virtualPathToPreassembedFile = virtualPathToPreassembedFile; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment