Trong ứng dụng thử nghiệm ASP.Net MVC4 đơn giản, tôi đã cài đặt gói NuGet không có dấu chấm và followed this tutorial.Gói ASP.Net MVC4 cho ít tệp không được hiển thị khi gỡ lỗi được đặt thành false
Các tệp .less
của tôi đang được phân tích cú pháp chính xác thành CSS và hoạt động tốt khi debug=true
.
<link href="/Public/less/main.less" rel="stylesheet"/>
<link href="/Public/less/home.less" rel="stylesheet"/>
<link href="/Public/less/a.less" rel="stylesheet"/>
<link href="/Public/less/b.less" rel="stylesheet"/>
<link href="/Public/less/c.less" rel="stylesheet"/>
Tuy nhiên khi tôi đặt debug=false
để có nó rút gọn và kết hợp với một kiểu duy nhất, tôi có được điều này:
<link href="/Public/less?v=" rel="stylesheet"/> // NOT WORKING!
Dưới đây là tập tin cấu hình bó của tôi; một lần nữa, lấy trực tiếp từ hướng dẫn:
public class BundleConfig
{
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
public static void RegisterBundles(BundleCollection bundles)
{
// Compile .less files and create a bundle for them.
var lessBundle = new Bundle("~/Public/less").Include(
"~/Public/less/main.less",
"~/Public/less/home.less",
"~/Public/less/a.less",
"~/Public/less/b.less",
"~/Public/less/c.less");
lessBundle.Transforms.Add(new LessTransform());
lessBundle.Transforms.Add(new CssMinify());
bundles.Add(lessBundle);
}
}
Và trong file Layout của tôi:
<head>
@Styles.Render("~/Public/less")
</head>
Và đây là lớp LessTransform tôi:
public class LessTransform : IBundleTransform
{
public void Process(BundleContext context, BundleResponse response)
{
response.Content = dotless.Core.Less.Parse(response.Content);
response.ContentType = "text/css";
}
}
Bất kỳ ý tưởng về lý do tại sao các bó không hoạt động đúng trên debug=false
?
Bạn có thể thử với câu trả lời này: http://stackoverflow.com/questions/9593254/mvc4-less-bundle-import-directory Ông sử dụng gói BundleTransformer.Less. Nó có thể giúp bạn ... – freshbm