T4MVC 处理使用 Chirpy 生成的缩小的 js 和 css 文件
我在 ASP.Net MVC 3 网站中使用 T4MVC 和 Chirpy 插件,我很喜欢它们。只有 T4MVC 似乎无法处理使用 Chirpy 和 .yui.js javascript 文件生成的缩小的 js 文件。 Chirpy 正在生成 .min.js 文件,但默认 T4MVC 脚本需要 .yui.min.js。
我对 T4MVC 进行了以下调整以使其正常工作 在 T4MVC.tt.settings.t4 中,我添加了
const string ChirpyJSExtension = ".yui";
在 T4MVC.tt 的第 983 行中,我更改了代码,
if (!ExcludedStaticFileExtensions.Any(extension => projectItem.Name.EndsWith(extension, StringComparison.OrdinalIgnoreCase))) {
// if it's a non-minified javascript file
if (projectItem.Name.EndsWith(".js") && !projectItem.Name.EndsWith(".min.js")) {
if (AddTimestampToStaticLink(projectItem)) { #>
public static readonly string <#=Sanitize(projectItem.Name.Replace(ChirpyJSExtension,string.Empty))#> = T4MVCHelpers.IsProduction() && T4Extensions.FileExists(URLPATH + "/<#=projectItem.Name.Replace(ChirpyJSExtension,string.Empty).Replace(".js", ".min.js")#>") ? Url("<#=projectItem.Name.Replace(ChirpyJSExtension,string.Empty).Replace(".js", ".min.js")#>")+"?"+T4Extensions.TimestampString(URLPATH + "/<#=projectItem.Name#>") : Url("<#=projectItem.Name#>")+"?"+T4Extensions.TimestampString(URLPATH + "/<#=projectItem.Name#>");
<#+} else {#>
public static readonly string <#=Sanitize(projectItem.Name.Replace(ChirpyJSExtension,string.Empty))#> = T4MVCHelpers.IsProduction() && T4Extensions.FileExists(URLPATH + "/<#=projectItem.Name.Replace(ChirpyJSExtension,string.Empty).Replace(".js", ".min.js")#>") ? Url("<#=projectItem.Name.Replace(ChirpyJSExtension,string.Empty).Replace(".js", ".min.js")#>") : Url("<#=projectItem.Name#>");
<#+} #>
<#+}
// if it's a non-minified css file
else if (projectItem.Name.EndsWith(".css") && !projectItem.Name.EndsWith(".min.css")) {
if (AddTimestampToStaticLinks) { #>
public static readonly string <#=Sanitize(projectItem.Name)#> = T4MVCHelpers.IsProduction() && T4Extensions.FileExists(URLPATH + "/<#=projectItem.Name.Replace(ChirpyJSExtension,string.Empty).Replace(".js", ".min.js")#>") ? Url("<#=projectItem.Name.Replace(ChirpyJSExtension,string.Empty).Replace(".css", ".min.css")#>")+"?"+T4Extensions.TimestampString(URLPATH + "/<#=projectItem.Name#>") : Url("<#=projectItem.Name#>")+"?"+T4Extensions.TimestampString(URLPATH + "/<#=projectItem.Name#>");
<#+} else {#>
public static readonly string <#=Sanitize(projectItem.Name)#> = T4MVCHelpers.IsProduction() && T4Extensions.FileExists(URLPATH + "/<#=projectItem.Name.Replace(ChirpyJSExtension,string.Empty).Replace(".js", ".min.js")#>") ? Url("<#=projectItem.Name.Replace(ChirpyJSExtension,string.Empty).Replace(".css", ".min.css")#>") : Url("<#=projectItem.Name#>");
<#+} #>
<#+}
else if (AddTimestampToStaticLink(projectItem)) { #>
public static readonly string <#=Sanitize(projectItem.Name)#> = Url("<#=projectItem.Name#>")+"?"+T4Extensions.TimestampString(URLPATH + "/<#=projectItem.Name#>");
<#+}
else { #>
public static readonly string <#=Sanitize(projectItem.Name)#> = Url("<#=projectItem.Name#>");
<#+}
} #>
我讨厌编辑这样的包含脚本,但我没有看到其他解决方案。
那么有没有人有更好的解决方案来保留默认的 T4MVC 脚本呢?
I am using T4MVC and the Chirpy plugin in an ASP.Net MVC 3 website and I am loving both of them. Only T4MVC can't seem to handle the minified js files generated with Chirpy and .yui.js javascript files.
Chirpy is generating .min.js files but the default T4MVC script expects .yui.min.js.
I have made the following adjustments to T4MVC to make it work
In T4MVC.tt.settings.t4 I have added
const string ChirpyJSExtension = ".yui";
And in T4MVC.tt on line 983 I have changed the code in
if (!ExcludedStaticFileExtensions.Any(extension => projectItem.Name.EndsWith(extension, StringComparison.OrdinalIgnoreCase))) {
// if it's a non-minified javascript file
if (projectItem.Name.EndsWith(".js") && !projectItem.Name.EndsWith(".min.js")) {
if (AddTimestampToStaticLink(projectItem)) { #>
public static readonly string <#=Sanitize(projectItem.Name.Replace(ChirpyJSExtension,string.Empty))#> = T4MVCHelpers.IsProduction() && T4Extensions.FileExists(URLPATH + "/<#=projectItem.Name.Replace(ChirpyJSExtension,string.Empty).Replace(".js", ".min.js")#>") ? Url("<#=projectItem.Name.Replace(ChirpyJSExtension,string.Empty).Replace(".js", ".min.js")#>")+"?"+T4Extensions.TimestampString(URLPATH + "/<#=projectItem.Name#>") : Url("<#=projectItem.Name#>")+"?"+T4Extensions.TimestampString(URLPATH + "/<#=projectItem.Name#>");
<#+} else {#>
public static readonly string <#=Sanitize(projectItem.Name.Replace(ChirpyJSExtension,string.Empty))#> = T4MVCHelpers.IsProduction() && T4Extensions.FileExists(URLPATH + "/<#=projectItem.Name.Replace(ChirpyJSExtension,string.Empty).Replace(".js", ".min.js")#>") ? Url("<#=projectItem.Name.Replace(ChirpyJSExtension,string.Empty).Replace(".js", ".min.js")#>") : Url("<#=projectItem.Name#>");
<#+} #>
<#+}
// if it's a non-minified css file
else if (projectItem.Name.EndsWith(".css") && !projectItem.Name.EndsWith(".min.css")) {
if (AddTimestampToStaticLinks) { #>
public static readonly string <#=Sanitize(projectItem.Name)#> = T4MVCHelpers.IsProduction() && T4Extensions.FileExists(URLPATH + "/<#=projectItem.Name.Replace(ChirpyJSExtension,string.Empty).Replace(".js", ".min.js")#>") ? Url("<#=projectItem.Name.Replace(ChirpyJSExtension,string.Empty).Replace(".css", ".min.css")#>")+"?"+T4Extensions.TimestampString(URLPATH + "/<#=projectItem.Name#>") : Url("<#=projectItem.Name#>")+"?"+T4Extensions.TimestampString(URLPATH + "/<#=projectItem.Name#>");
<#+} else {#>
public static readonly string <#=Sanitize(projectItem.Name)#> = T4MVCHelpers.IsProduction() && T4Extensions.FileExists(URLPATH + "/<#=projectItem.Name.Replace(ChirpyJSExtension,string.Empty).Replace(".js", ".min.js")#>") ? Url("<#=projectItem.Name.Replace(ChirpyJSExtension,string.Empty).Replace(".css", ".min.css")#>") : Url("<#=projectItem.Name#>");
<#+} #>
<#+}
else if (AddTimestampToStaticLink(projectItem)) { #>
public static readonly string <#=Sanitize(projectItem.Name)#> = Url("<#=projectItem.Name#>")+"?"+T4Extensions.TimestampString(URLPATH + "/<#=projectItem.Name#>");
<#+}
else { #>
public static readonly string <#=Sanitize(projectItem.Name)#> = Url("<#=projectItem.Name#>");
<#+}
} #>
I hate editing included scripts like this but I saw no other solution.
So does anyone have a better solution for this that leaves the default T4MVC script alone?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
新版本的 chirpy 解决了这个问题。
http://chirpy.codeplex.com/SourceControl/changeset/changes/ab7715fabba6
New version of chirpy solve this problem.
http://chirpy.codeplex.com/SourceControl/changeset/changes/ab7715fabba6