This article is a mirror article of machine translation, please click here to jump to the original article.

View: 5870|Reply: 2

[Source] Practical Operation: Use BundleTransformer to replace System.Web.Optimization

[Copy link]
Posted on 2022-11-12 11:05:08 | | | |
Requirements: The modular extension of System.Web.Optimization (also known as the Microsoft ASP.NET Web Optimization Framework) that comes with Microsoft ASP.NET MVC is outdated and has not been updated for a long time (Last updated: 2014/2/20, there are some bugs that no one has fixed), introducing bootstrap 4 will cause an error, using a third-party Bundle Transformer to replace the default one.

About bundled compression:The hyperlink login is visible.

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

NuGet address:The hyperlink login is visible.

System.Web.Optimization will give the following error when bundling Bootstrap 4:

/* 未能缩小。正在返回未缩小的内容。
(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 of System.Web.Optimization (also known as the Microsoft ASP.NET Web Optimization Framework). StyleTransformer and ScriptTransformer classes, which are included in the core of Bundle Transformer and implement the IBundleTransform interface. They are designed to replace the standard classes: CssMinify and JsMinify.

The main differences between StyleTransformer and class and standard implementations ScriptTransformer: the ability to exclude unnecessary assets when adding assets from the directory, does not produce rescaling of pre-minified assets, supports automatic conversion of relative paths to absolute paths in CSS code (by using UrlRewritingCssPostProcessor), etc. These classes do not produce minification of the code at runtime, but this functionality can be added by installing minifier-modules (the modules available now are based on Microsoft Ajax Minifier, YUI Compressor for .NET, NUglify, Google Closure Compiler, Douglas Crockford's JSMin, Dean Edwards' Packer, UglifyJS by Mihai Bazon, CSSO (CSS Optimizer) by Sergey Kryzhanovsky, WebGrease, and Clean-css). In addition, you can install translation modules to implement code translation in intermediate languages (LESS, Sass, SCSS, CoffeeScript, TypeScript, Mustache (using Hogan), and Handlebars). In addition to this, there is a third type of module in Bundle Transformer - postprocessors. The postprocessor runs after the translator and before the compressor. The following postprocessors are now available: URL Rewrite CSS Postprocessor (included in the core) and Postprocessor modules based on Andrey Sitnik's Autoprefixer.

GitHub address:The hyperlink login is visible.
Documentation Tutorial:The hyperlink login is visible.

BundleTransformer.Core just provides bundling functionality andFeatures such as compression obfuscation are not availableIf compression and other functions need to be introduced into other modules, this article will useBundleTransformer.NUglifyThe extension module compresses the bundled CSS and JS outputs.

BundleTransformer.NUglify contains two minifier adapters: "NUglifyCssMinifier" (for miniaturization of CSS code) and "NUglifyJsMinifier" (for miniaturization of JS code). These adapters perform minification (https://github.com/trullock/NUglify).
Therefore, the project can directly introduce BundleTransformer.NUglify with the following NuGet command:

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

At this point, access the /plugins/site/login link, the css resource andNot compressed, you also need to modify the configuration of web.config to make "NUglifyCssMinifier" the default CSS minifier program.

UrlRewritingCssPostProcessor: supports automatic conversion of relative paths to absolute paths in CSS code, etc.

Locate the web.config file/configuration/bundleTransformer/core/cssnode, modified as follows:

The complete configuration is as follows:

(End)





Previous:[Actual combat]. NET/C# application crashes and exceptions automatically generate DMP dump files
Next:Can the network card also be virtualized? Detailed explanation of network card virtualization technology Macvlan
Posted on 2022-11-15 18:23:22 |
Learn a little
 Landlord| Posted on 2023-7-10 18:35:50 |
ASP.NET Core (twelve) front-end JS, CSS bundling, and compression
https://www.itsvse.com/thread-10282-1-1.html

Asp.net MVC Bundle packages all CSS files together
https://www.itsvse.com/thread-4921-1-1.html
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com