如何使用 bundle transformer 来 Minify CSS 或者 JS
How to use bundle transformer to Minify CSS or JS
我想使用 bundle transformer 来捆绑和缩小我的 css collection
, 但我试过了它不起作用
这是我的代码,请给我一些建议,谢谢。
var nullBuilder = new NullBuilder();
var cssTransformer = new StyleTransformer(new CleanCssMinifier());
var nullOrderer = new NullOrderer();
BundleResolver.Current = new CustomBundleResolver();
var commonStylesBundle = new Bundle("~/bundles/css/site");
commonStylesBundle.IncludeDirectory("~/Content/sass", "*.css");
commonStylesBundle.Builder = nullBuilder;
commonStylesBundle.Transforms.Add(cssTransformer);
commonStylesBundle.Orderer = nullOrderer;
bundles.Add(commonStylesBundle);
它总是像这样输出 html:
<link href="/Content/sass/card.css?bundleVirtualPath=%7e%2fbundles%2fcss%2fsite" rel="stylesheet"/>
<link href="/Content/sass/header.css?bundleVirtualPath=%7e%2fbundles%2fcss%2fsite" rel="stylesheet"/>
<link href="/Content/sass/login.css?bundleVirtualPath=%7e%2fbundles%2fcss%2fsite" rel="stylesheet"/>
您需要在配置中将调试模式设置为 false。或者在代码中执行以下操作-
BundleTable.EnableOptimizations = true;
我想使用 bundle transformer 来捆绑和缩小我的 css collection , 但我试过了它不起作用
这是我的代码,请给我一些建议,谢谢。
var nullBuilder = new NullBuilder();
var cssTransformer = new StyleTransformer(new CleanCssMinifier());
var nullOrderer = new NullOrderer();
BundleResolver.Current = new CustomBundleResolver();
var commonStylesBundle = new Bundle("~/bundles/css/site");
commonStylesBundle.IncludeDirectory("~/Content/sass", "*.css");
commonStylesBundle.Builder = nullBuilder;
commonStylesBundle.Transforms.Add(cssTransformer);
commonStylesBundle.Orderer = nullOrderer;
bundles.Add(commonStylesBundle);
它总是像这样输出 html:
<link href="/Content/sass/card.css?bundleVirtualPath=%7e%2fbundles%2fcss%2fsite" rel="stylesheet"/>
<link href="/Content/sass/header.css?bundleVirtualPath=%7e%2fbundles%2fcss%2fsite" rel="stylesheet"/>
<link href="/Content/sass/login.css?bundleVirtualPath=%7e%2fbundles%2fcss%2fsite" rel="stylesheet"/>
您需要在配置中将调试模式设置为 false。或者在代码中执行以下操作-
BundleTable.EnableOptimizations = true;