private static void WriteMinFile(string filePath, string bundlePath, string content, string extension) { string minPath = bundlePath.Replace(Path.GetExtension(bundlePath), ".min" + Path.GetExtension(bundlePath)); if (extension.Equals(".js", StringComparison.OrdinalIgnoreCase)) { JavaScriptSaveListener.Minify(bundlePath, minPath, true); MarginBase.AddFileToProject(filePath, minPath); if (WESettings.GetBoolean(WESettings.Keys.GenerateJavaScriptSourceMaps)) { MarginBase.AddFileToProject(filePath, minPath + ".map"); } MarginBase.AddFileToProject(filePath, minPath + ".gzip"); } else if (extension.Equals(".css", StringComparison.OrdinalIgnoreCase)) { string minContent = MinifyFileMenu.MinifyString(extension, content); ProjectHelpers.CheckOutFileFromSourceControl(minPath); using (StreamWriter writer = new StreamWriter(minPath, false, new UTF8Encoding(true))) { writer.Write(minContent); } MarginBase.AddFileToProject(filePath, minPath); if (WESettings.GetBoolean(WESettings.Keys.CssEnableGzipping)) { CssSaveListener.GzipFile(filePath, minPath, minContent); } } }
private static void MinifyFile(string file, string minFile, CodeSettings settings, bool isBundle) { Minifier minifier = new Minifier(); if (!isBundle) { minifier.FileName = Path.GetFileName(file); } string content = minifier.MinifyJavaScript(File.ReadAllText(file), settings); if (WESettings.GetBoolean(WESettings.Keys.GenerateJavaScriptSourceMaps)) { content += Environment.NewLine + "//@ sourceMappingURL=" + Path.GetFileName(minFile) + ".map"; } ProjectHelpers.CheckOutFileFromSourceControl(minFile); using (StreamWriter writer = new StreamWriter(minFile, false, new UTF8Encoding(true))) { writer.Write(content); } if (WESettings.GetBoolean(WESettings.Keys.JavaScriptEnableGzipping)) { CssSaveListener.GzipFile(file, minFile, content); } }