MVC4 Less Bundle @import 目录 [英] MVC4 Less Bundle @import Directory

查看:22
本文介绍了MVC4 Less Bundle @import 目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 MVC4 捆绑来对我的一些 less 文件进行分组,但看起来我正在使用的导入路径已关闭.我的目录结构是:

I'm trying to use MVC4 bundling to group some of my less files, but it looks like the import path I'm using is off. My directory structure is:

static/
    less/
        mixins.less
        admin/
            user.less

在 user.less 中,我尝试使用以下方法导入 mixins.less:

In user.less, I'm attempting to import mixins.less using this:

@import "../mixins.less";

以前使用带有 dotless 的 chirpy 时,这曾经对我有用,但现在我注意到 ELMAH 生我的气,说:

This used to work for me before when using chirpy with dotless, but now I noticed ELMAH was getting mad at me, saying this:

System.IO.FileNotFoundException: 
    You are importing a file ending in .less that cannot be found.
File name: '../mixins.less'

我应该在 MVC4 中使用不同的 @import 吗?

Am I supposed to use a different @import with MVC4?

这是我用来尝试此操作的 less 类和 global.asax.cs 代码:

Here's the less class and global.asax.cs code I'm using to attempt this:

LessMinify.cs

...
public class LessMinify : CssMinify
{
    public LessMinify() {}

    public override void Process(BundleContext context, BundleResponse response)
    {
        response.Content = Less.Parse(response.Content);
        base.Process(context, response);
    }
}
...

Global.asax.cs

...
DynamicFolderBundle lessFB = 
    new DynamicFolderBundle("less", new LessMinify(), "*.less");
    
BundleTable.Bundles.Add(lessFB);

Bundle AdminLess = new Bundle("~/AdminLessBundle", new LessMinify());
...
AdminLess.AddFile("~/static/less/admin/user.less");
BundleTable.Bundles.Add(AdminLess);
...

推荐答案

我写了一篇关于 使用 LESS CSS 和 MVC4 Web 优化.

基本上归结为使用 BundleTransformer.Less Nuget Package 并更改您的 BundleConfig.cs.

It basically boils down to using the BundleTransformer.Less Nuget Package and changing up your BundleConfig.cs.

使用引导程序进行测试.

Tested with bootstrap.

应该提到我这么说的原因,是我也遇到了@import 目录结构问题,而这个库可以正确处理它.

Should mention the reason I say this, is I also ran into the @import directory structure issue, and this library handles it correctly.

这篇关于MVC4 Less Bundle @import 目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆