minify module properly?

Posted on
  • I just tried to use the Closure Compiler directly through the website and using the minify.js script. Neither way would remove the constants. C's contents stays the same. Is there another method that's used for minifying files for the website?

  • Yep, you basically wrap it in (function() { ... })(), then remove the same text after it's been through.

  • Okay. I've tried that and it won't minimise the "C" private constants. Do you just use simple optimisation?

  • I was never able to make it minify constants either.

  • Hmm... sure you defined C with var? Try this:

    (function() {
      var C = {
        foo : 42
      };
      exports.hello = function() { return C.foo+1; }
    })()
    

    Just done and it compiles to:

    (function(){exports.hello=function(){ret­urn 43}})();
    
  • I just tried copying the same thing in as I did yesterday and it worked this time. :S I'm sorry, I must be going crazy...

  • Just for anyone else having trouble with minifying, errors in your code can affect it. I think that's what was messing me up, I had a couple of things that weren't causing error messages or being picked up by JSHint but they were stopping minification.

  • They were stopping the Web IDE from working but you weren't being told?

    Can you post up a small example? If the online minification fails then it should report error messages. Perhaps the new offline minification doesn't report errors correctly?

  • My code was minifying, just not completely. It's not a problem with the IDE, or even the compiler I suppose, just a quirk in the process.

    Private constants was the main thing that wasn't minifying. One of the reasons was that in one of my functions I was referring to a value not listed in the array, which wouldn't normally be a problem until that function is called. It looks like closure compiler just skipped C and moved on without an error.

  • Ahh, interesting. Thanks for letting me know!

    Yes, I suppose it's still valid JS so it can't really complain about it :) I wonder if there's a 'pedantic' mode where it'll tell you all this stuff - it could be really useful.

  • Looks like you get a warning if you set warning_level to VERBOSE. I think I should run all my code through this just to find the errors that nothing else picks up!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

minify module properly?

Posted by Avatar for the1laz @the1laz

Actions