Taritsyn / BundleTransformer

Bundle Transformer - a modular extension for System.Web.Optimization (also known as the Microsoft ASP.NET Web Optimization Framework).
Apache License 2.0
130 stars 19 forks source link

Error while compressing Expected semicolon or closing curly-brace, found '-' #46

Closed jitangupta closed 3 years ago

jitangupta commented 3 years ago

Getting error when enable optimizations is true.

BundleTable.EnableOptimizations = true;

Similar Issue: https://github.com/trullock/NUglify/pull/46 Error while compiling the :root https://github.com/trullock/NUglify/pull/46/files#diff-1fc1d5d1bf6b24928485c0cf59bcd6f7894809d95f5552b52209ca3b222f1b01

Work-around tried unsuccessfully as this also fails when BundleTable.EnableOptimizations = true; Working as expected when BundleTable.EnableOptimizations = false; (in development mode)

https://stackoverflow.com/a/54088086/8178474

public class MyStyleBundle : Bundle
{
    public MyStyleBundle(string virtualPath) : base(virtualPath, new MyCssMinify())
    {
    }

    public MyStyleBundle(string virtualPath, string cdnPath) : base(virtualPath, cdnPath, new MyCssMinify())
    {
    }
}

public class MyCssMinify : IBundleTransform
{
    internal static readonly MyCssMinify Instance = new MyCssMinify();

    internal static string CssContentType = "text/css";

    public virtual void Process(BundleContext context, BundleResponse response)
    {
        if (context == null)
        {
            throw new ArgumentNullException("context");
        }
        if (response == null)
        {
            throw new ArgumentNullException("response");
        }
        if (!context.EnableInstrumentation)
        {
            // CssCompress.Go- This is your CSS compression implementation
            // You can use the library " Uglify"
            response.Content = Uglify.Css(response.Content);
        }
        response.ContentType = CssContentType;
    }
}

Screen shot: image

Taritsyn commented 3 years ago

Hello, Jitan!

This is a error at the Microsoft Ajax Minifier library level. Replace the BundleTransformer.MicrosoftAjax module by the BundleTransformer.NUglify module.

Taritsyn commented 3 years ago

If this error still occurs, try to add in the Web.config file the following setting:

<configuration>
  …
  <bundleTransformer …>
    …
    <nuglify>
      <css ignoreErrorList="CSS1062" />
      …
    </nuglify>
    …
  </bundleTransformer>
  …
</configuration>
jitangupta commented 3 years ago

Thank you for replying @Taritsyn,

I am currently testing the first suggestion. Sure will add the second one also.

Will update once done

jitangupta commented 3 years ago

Thank you @Taritsyn, It is working as expected.