MVC4少捆绑@import目录 [英] MVC4 Less Bundle @import Directory

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

问题描述

我试图用MVC4捆绑到组我的一些少的文件,但它看起来像我使用的导入路径是关闭的。我的目录结构是:

 静态/
    减/
        mixins.less
        管理员/
            user.less

在user.less,我试图用这个导入mixins.less:

  @import../mixins.less

这习惯使用扢以带点时前为我工作,但现在我发现ELMAH是越来越气死我了,说这句话的:

  System.IO.FileNotFoundException:找不到
    要导入在.LESS结尾的文件无法被发现。
文件名:'../mixins.less

我应该使用不同的 @import 与MVC4?

一些额外的信息

下面是不太类的global.asax.cs code我使用尝试此:

LessMinify.cs

  ...
公共类LessMinify:CssMinify
{
    公共LessMinify(){}    公共覆盖无效过程(BundleContext的背景下,BundleResponse响应)
    {
        response.Content = Less.Parse(response.Content);
        base.Process(背景下,响应);
    }
}
...

的Global.asax.cs

  ...
DynamicFolderBundle lessFB =
    新DynamicFolderBundle(少,新LessMinify(),* .LESS);BundleTable.Bundles.Add(lessFB);捆绑AdminLess =新包(〜/ AdminLessBundle,新LessMinify());
...
AdminLess.AddFile(〜/静态/更少/管理/ user.less);
BundleTable.Bundles.Add(AdminLess);
...


解决方案

我写了一个快速的博客文章的少用CSS随着MVC4网络优化

这基本上可以归结为使用 BundleTransformer.Less的NuGet包并改变你的BundleConfig.cs。

测试与引导。

编辑:要提到我这样说的原因,是我也跑进了@import目录结构的问题,这个库能够正确地处理它。

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

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

@import "../mixins.less";

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'

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

Some additional info

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);
...

解决方案

I've written a quick blog post about Using LESS CSS With MVC4 Web Optimization.

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

Tested with bootstrap.

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

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

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