架构师_程序员_码农网

Retrieve password
Register

QQ登录

Just one step to get started

Search
View:3068|Reply: 2
打印 上一主题 下一主题

[Archive][Hands-on] Replacing System.Web.Optimization with BundleTransformer

[Copy link]
跳转到指定楼层
owner
发表于 2022-11-12 11:05:08| 看该作者回帖奖励|ReverseBrowse|Read Mode
Requirement: The modular extension of System.Web.Optimization (also known as Microsoft ASP.NET Web Optimization Framework) that comes with Microsoft ASP.NET MVC is outdated and hasn't been updated for a long time ( last update: 2014/2/20, there are a few bugs that no one has fixed ). bootstrap 4 will report an error, use a third-party Bundle Transformer to replace the default one.

About bundle compression: https: //learn.microsoft.com/en-us/aspnet/mvc/overview/performance/bundling-and-minification

System.Web.Optimization:F:\... \packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll

NuGet Address: https: //www.nuget.org/packages/Microsoft.AspNet.Web.Optimization

System.Web.Optimization will report the following error when bundling and compressing Bootstrap 4:

/* Failed to shrink. Returning unreduced content.
(6,10): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,25): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,42): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,59): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,74): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,88): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,105): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,122): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,138): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,153): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,168): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,181): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,196): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,216): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,234): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,254): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,272): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,287): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,305): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,322): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,338): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,353): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,371): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,393): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,415): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,437): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,460): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
(6,644): run-time error CSS1062: Expected semicolon or closing curly-brace, found '-'
/*!
/*!
* Bootstrap v4.1.3 (https://getbootstrap.com/)
* Copyright 2011-2018 The Bootstrap Authors
* Copyright 2011-2018 Twitter, Inc.
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)


Bundle Transformer

Bundle Transformer - a modular extension to System.Web.Optimization (also known as the Microsoft ASP.NET Web Optimization Framework). StyleTransformer and ScriptTransformer classes, included in the Bundle Transformer core and implement the IBundleTransform interface. They are intended to replace the standard classes: CssMinify and JsMinify.

Key differences between the StyleTransformer and classes and the standard implementation ScriptTransformer: the ability to exclude unnecessary assets when adding assets from a catalog, no re-shrinking of pre-reduced assets, support for automatic conversion of relative paths to absolute paths in CSS code (by using the UrlRewritingCssPostProcessor), and so on. These classes do not shrink code at runtime, but this can be added by installing minifier-modules (now available modules based on Microsoft Ajax Minifier, YUI Compressor for .NET, NUglify, Google Closure compiler, Douglas Crockford's JSMin, Dean Edwards' Packer, Mihai Bazon's UglifyJS, Sergey Kryzhanovsky's CSSO (CSS Optimizer), WebGrease and Clean-css). Additionally, you can install translation modules that enable intermediate languages (code translation for LESS, Sass, SCSS, CoffeeScript, TypeScript, Mustache (using Hogan) and Handlebars). In addition to this, there is a third type of module in Bundle Transformer - the post-processor. Postprocessors run after the translator and before the compressor. The following postprocessors are now available: URL rewriting CSS postprocessor (included in the core) and a postprocessor module based on Andrey Sitnik's Autoprefixer.

GitHub address: https: //github.com/Taritsyn/BundleTransformer
Documentation tutorial: https: //github.com/Taritsyn/BundleTransformer/wiki/Examples-of-usage

BundleTransformer.Core only provides bundling functionality, it does not provide compression and obfuscation features, if you need compression and other features you need to introduce other modules, this article uses the BundleTransformer.NUglify extension module to compress the output of the bundled css and js.

BundleTransformer.NUglify contains two minifier adapters: "NUglifyCssMinifier" (for CSS code minification) and "NUglifyJsMinifier " (for miniaturizing JS code). These adapters perform minification by using NUglify (https://github.com/trullock/NUglify).
So, the project can just introduce BundleTransformer.NUglify directly, and the NuGet command is as follows:

After installation, modify the BundleConfig.cs configuration with the following code:

At this point, visit the /Plugins/site/login link, the css resources are not compressed, you still need to modify the configuration of web.config, so that "NUglifyCssMinifier" becomes the default CSS minifier program.

One of them is UrlRewritingCssPostProcessor: it supports automatic conversion of relative paths to absolute paths in CSS code.

Find the /configuration/bundleTransformer/core/css node in the web.config file and change it as follows:

The full configuration looks like this:

(end)





Previous: NET/C# application crash abnormal exit automatically generate DMP dump file
Next: NIC virtualization? NIC virtualization technology macvlan details
Code farmer network, only published in the process of practice, encountered technical difficulties, do not mislead others.
fyxh66 fyxh66
Posted on 2022-11-15 18:23:22|Only View Author
I'm not sure if I'm going to be able to do that.
The code farmer network, only published in the process of practice, encountered technical difficulties, do not mislead others.
nike air max 90 pas cher
楼主 | 发表于 2023-7-10 18:35:50| 看该作者
ASP.NET Core (XII) front-end JS, CSS bundling and compression
h ttps:// www.itsvse.com/thread-10282-1-1.html

Asp.net mvc bundle to package all css files together
h ttps:// www.itsvse.com/thread-4921-1-1.html
Code farmer network, only published in the process of practice, encountered technical difficulties, do not mislead others.
You need to log in before you can post back Log in | Register

This version of the integral rules

DISCLAIMER:
All software, programming materials or articles released by the code farmer network is limited to study and research purposes; the above content shall not be used for commercial or illegal purposes, otherwise, all the consequences please user responsible. This site information from the network, copyright dispute has nothing to do with this site. You must completely remove the above content from your computer within 24 hours of downloading. If you like the program, please support the genuine software, buy registration and get better genuine service. If there is any infringement, please contact us by email to deal with it.

Mail To:help@itsvse.com

QQ| ( ICP备14021824号-2 )|Sitemap

GMT+8, 2024-9-19 05:17

Quick ReplyBack to topBack to list