标签: bundling-and-minification

如何配置MVC的样式捆绑顺序?

我的网络应用程序正在使用jquery-ui和jqgrid设置的大图标.
为了在升级jquery-ui或jqgrid时轻松维护对CSS的更改以容纳更大的图标,我有一个单独的CSS文件,我有一堆覆盖.

你可以想象这个覆盖文件必须包含在jquery-ui样式表和jqgrid样式表之后.

我将所有的样式表都放到了这样的包中

bundles.Add(new StyleBundle("~/Content/dark-hive/allstyles").Include(
    "~/Content/dark-hive/jquery-ui-1.8.23.custom.css",
    "~/Content/ui.jqgrid.css",
    "~/Content/jquery-ui-fixes.css",
    "~/Content/icons.css",
    "~/Content/site.css"));
Run Code Online (Sandbox Code Playgroud)

但它正如此呈现!

<link href="/Content/dark-hive/jquery-ui-1.8.23.custom.css" rel="stylesheet"/>
<link href="/Content/jquery-ui-fixes.css" rel="stylesheet"/>
<link href="/Content/ui.jqgrid.css" rel="stylesheet"/>
<link href="/Content/icons.css" rel="stylesheet"/>
<link href="/Content/site.css" rel="stylesheet"/>
Run Code Online (Sandbox Code Playgroud)

如何配置我的包以正确的顺序呈现?

更新
确定,这是愚蠢但它的工作.

无论我做什么,文件总是会错误地呈现.所以我尝试了一些愚蠢的东西,首先添加了jquery-ui-fixes.css,最后添加了jquery-ui-1.8.23.custom.css.

突然我的命令是

<link href="/Content/jquery-ui-fixes.css" rel="stylesheet"/>
<link href="/Content/dark-hive/jquery-ui-1.8.23.custom.css" rel="stylesheet"/>
<link href="/Content/ui.jqgrid.css" rel="stylesheet"/>
<link href="/Content/icons.css" rel="stylesheet"/>
<link href="/Content/site.css" rel="stylesheet"/>
Run Code Online (Sandbox Code Playgroud)

我将我的javascript文件重命名为jqueryuifixes.css,现在它的顺序保存在较低的js文件中.

我想如果一个样式表有一个 - 在名称中它首先由于某种原因被优先排序,并且它的顺序与其他文件一起维护 - 在其中.

如果有人能解释这个,我会给他们支票.

asp.net-mvc-4 bundling-and-minification

23
推荐指数
2
解决办法
1万
查看次数

没有ASP.NET MVC的捆绑和缩小

是否可以在没有MVC项目的情况下使用Microsoft.AspNet.Web.Optimization中的捆绑和缩小?

我正在创建一个与REST API通信的AngularJS站点.对于REST API,我使用的是ASP.NET Web API.我还创建了一个"ASP.NET空Web应用程序".此项目中只有HTML,js和CSS文件(以及web.config).我想将我的js和CSS文件捆绑和缩小,但我不想创建一个MVC项目来获得它.可能吗?

c# asp.net asp.net-mvc visual-studio-2012 bundling-and-minification

23
推荐指数
2
解决办法
8927
查看次数

ASP.net捆绑包是否会自动缩小文件?

我正在使用ASP.net MVC 4.就像问题所述,如果我将一堆JS文件(或CSS,就此而言)放入一个包中,它会自动缩小吗?例如,我的包应该是:

        bundles.Add(new ScriptBundle("~/bundles/exampleBundle").Include(
            "~/Scripts/jquery-masked.js"
            "~/Scripts/jquery.idletimer.js"
            ));
Run Code Online (Sandbox Code Playgroud)

或者它应该最初包括缩小的文件:

        bundles.Add(new ScriptBundle("~/bundles/exampleBundle").Include(
            "~/Scripts/jquery-masked.min.js"
            "~/Scripts/jquery.idletimer.min.js"
            ));
Run Code Online (Sandbox Code Playgroud)

??

编辑:现在我想知道捆绑.min文件是否会添加任何优化.它是否会提高性能,包括捆绑包中的.min文件而不是基本文件?(也许"minifier函数"需要一些时间?)

c# asp.net-mvc bundle bundling-and-minification

23
推荐指数
2
解决办法
1万
查看次数

从webpack缩小中排除模块

我们在单页面应用程序中使用WebPack.该应用程序部署到许多环境中.我们有一个要求,即应用程序需要在给定环境中调用特定端点.

为了给定环境提供端点地址,就是拥有一个环境模块.这是当前的解决方案(有很多,这不是问题的关键).但是,我们需要从缩小中排除config.js,以便在部署过程中将其覆盖.

config.js如下所示:

module.exports = {
    env: {
        endpointUrl: 'http://1.2.3.4',
        authUrl: 'http://5.6.7.8'
    }
};
Run Code Online (Sandbox Code Playgroud)

并使用以下内容引用:

const endpointUrl = config.env.endpointUrl;
const authUrl = config.env.authUrl;
Run Code Online (Sandbox Code Playgroud)

WebPack配置如下所示:

var webpack = require('webpack');
?
module.exports = {
    entry: {
        main: './src/js/main.jsx',
        login: './src/js/login-main.jsx'
    },
    output: {
        path: __dirname + '/dist',
        filename: '[name].bundle.js'
    },
    devtool: 'source-map',
    module: {
        loaders: [{
            test: /.jsx?$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
            plugins: ['transform-react-jsx'],
            query: {stage: 0}
        }, {
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loader: 'eslint-loader'
        }]
    },
    plugins: [
        new webpack.ProvidePlugin({
            fetch: …
Run Code Online (Sandbox Code Playgroud)

javascript bundling-and-minification webpack

23
推荐指数
2
解决办法
2万
查看次数

MVC4捆绑缓存头

我想更改从捆绑请求发送的缓存标头.目前它是变化的,User-Agent但我不希望它,有没有办法更改捆绑请求发送的标头?

快速查看System.Web.Optimization程序集后,我可以看到标题设置在Bundle.SetHeaders一个私有静态函数中,所以我认为它不可能,尽管我希望被证明是错误的.

c# asp.net asp.net-mvc-4 bundling-and-minification asp.net-optimization

21
推荐指数
1
解决办法
5334
查看次数

MVC4 Bundles - 没有Twitter Bootstrap图标

在调试模式下运行我的MVC4应用程序(因此没有缩小css/scripts)工作正常.一旦我在没有调试的情况下运行(css/scripts minified),我的Twitter Bootstrap图标就不会显示出来.这里的另一个线程建议使用bundles.IgnoreList.Clear().但这似乎对我不起作用.我的BundleConfig.RegisterBundles(...)看起来像这样:

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.IgnoreList.Clear();

    // Some JavaScript bundles only
    // ...

    bundles.Add(new StyleBundle("~/bundles/maincss").Include(
        "~/Content/bootstrap.css",
        "~/Content/bootstrap-responsive.css",
       "~/Content/my.css"));
    }
}
Run Code Online (Sandbox Code Playgroud)

所有软件包都是使用Nuget安装的(正如我所说,它在调试模式下工作正常).我的内容文件夹还包含bootstrap ... css文件的缩小版本,但不包含my.css的缩小版本.字形图标位于图像子文件夹中.

我的_Layout.cshtml看起来像这样:

<head>
    ...
    @Styles.Render("~/bundles/maincss")
</head>
Run Code Online (Sandbox Code Playgroud)

我应该补充一点,通过"非调试"模式,我的意思是在Web.config文件中设置debug ="false"选项:

<compilation debug="false" targetFramework="4.5" />
Run Code Online (Sandbox Code Playgroud)

有没有人知道为什么twitter引导程序图标不会以"非调试"模式显示?

谢谢Rob

css asp.net-mvc-4 twitter-bootstrap bundling-and-minification

21
推荐指数
2
解决办法
1万
查看次数

如何使用System JS Builder捆绑Angular 2?

我目前正在使用带有System JS Builder的System JS来捆绑我的应用程序,它的资产以及它引用的库.我的问题是我可以捆绑在index.html中明确引用的库,例如:

<script src="node_modules/es6-shim/es6-shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
Run Code Online (Sandbox Code Playgroud)

但是,我无法弄清楚如何捆绑Angular 2本身,或者至少是Angular 2所需的模块,因为它们实际上并未在HTML中引用.如何才能做到这一点?

bundling-and-minification systemjs angular

21
推荐指数
1
解决办法
2万
查看次数

如何从flutter中删除或识别未使用的包以减少项目的大小?

我在我的 flutter 项目中使用了一些不再需要的包,即wilddog_authand wilddog_sync,我可以从pubspec.yaml文件和我的 dart 文件中import 'package:wilddog_sync/wilddog_sync.dart'删除导入(也称为删除等)并删除 MainActivity.java 和 Xcode 项目中的导入,但是我无法清除 flutter、cocoapod 和 gradle 安装的未使用文件。现在flutter中有一个统一的命令可以一次删除所有未使用的包吗?

我敢肯定,使用flutter clean只删除build文件夹,并使用flutter packages get从删除软件包后pubspec.yaml不会删除软件包cocoapodgradle两种。

例如,在flutter cleanflutter packages get我重建项目:

Launching lib/main.dart on Android SDK built for x86 64 in debug mode...
Initializing gradle...
Resolving dependencies...
Running 'gradlew assembleDebug'...
Built build/app/outputs/apk/debug/app-debug.apk.
Installing build/app/outputs/apk/app.apk...
I/FlutterActivityDelegate(11331): onResume setting current activity to this
I/Choreographer(11331): Skipped 107 frames!  The application …
Run Code Online (Sandbox Code Playgroud)

bundling-and-minification flutter flutter-dependencies flutter-packages

20
推荐指数
2
解决办法
2万
查看次数

如何在运行时暂时禁用捆绑和缩小?

我需要能够暂时禁用单个请求的捆绑和缩小,以便调试JavaScript和CSS问题.我想在运行时通过向QueryString添加一个参数来执行此操作,如此...

http://domain.com/page?DisableOptimizations=true
Run Code Online (Sandbox Code Playgroud)

这是我正在考虑的方法.

protected void Application_BeginRequest(object sender, EventArgs e)
{
  // Enable for every request
  BundleTable.EnableOptimizations = true;

  // Disable for requests that explicitly request it
  bool disable;
  bool.TryParse(Context.Request.QueryString["DisableOptimizations"], out disable);
  if (disable)
  {
    BundleTable.EnableOptimizations = false;
  }
}
Run Code Online (Sandbox Code Playgroud)
  • 我是否在每个Web请求上设置此静态属性这一事实是否存在潜在问题?(Web应用程序将在Web场上运行)
  • 有没有更好的方法来处理这个?

c# asp.net asp.net-mvc bundling-and-minification asp.net-optimization

19
推荐指数
1
解决办法
2449
查看次数

是否可以从ASPX文件的代码中调用Scripts.Render或Styles.Render?

有没有办法@:Scripts/Styles.Render从代码后面复制助手的行为?

如果我使用该BundleTable.Bundles.ResolveBundleUrl方法引用捆绑包,则即使使用捆绑和缩小也会发生debug=true.我已经阅读了其他问题,通过使用前面提到的帮助程序,解决方案似乎非常明显.但在我的情况下,我在aspx中不知道bundle的名称,它是在运行时在后面的代码中生成的.

所以,我需要在后面的代码中添加引用,我找不到办法.

有办法吗?或者我将被迫在.aspx文件中执行此操作?

c# asp.net bundling-and-minification

19
推荐指数
2
解决办法
1万
查看次数