admin管理员组

文章数量:1418680

In my javascript I have some bits of code specifically used for debugging which I don't want to include in the live site. Is there a way I can semi-ment these bits of code so that they run as javascript normally, but that yui pressor thinks they're ments and removes them?

For example

for(key in modules) {
  try { 
     MyApp[key].init(modules[key].params);
  } catch (e) {
     console.log("Module " + key + " threw an error");
     break;
  }
}

I would like to be able to ment out the console.log bit automatically when pressing to deploy to the live site. So maybe wrap the code in something like

   //yuiIgnore
         console.log("Module " + key + " threw an error");
   //endyuiIgnore

In my javascript I have some bits of code specifically used for debugging which I don't want to include in the live site. Is there a way I can semi-ment these bits of code so that they run as javascript normally, but that yui pressor thinks they're ments and removes them?

For example

for(key in modules) {
  try { 
     MyApp[key].init(modules[key].params);
  } catch (e) {
     console.log("Module " + key + " threw an error");
     break;
  }
}

I would like to be able to ment out the console.log bit automatically when pressing to deploy to the live site. So maybe wrap the code in something like

   //yuiIgnore
         console.log("Module " + key + " threw an error");
   //endyuiIgnore
Share Improve this question edited Sep 27, 2010 at 10:09 wheresrhys asked May 13, 2010 at 10:30 wheresrhyswheresrhys 23.6k21 gold badges97 silver badges165 bronze badges 1
  • Can you please provide a sample of the code you're trying to minify BUT is not getting stripped out. Secondly, can you please provide the mand line you run to minify or the configuration settings (if you're using the .NET port). – Pure.Krome Commented Sep 24, 2010 at 12:23
Add a ment  | 

1 Answer 1

Reset to default 8

With regard specifically to console.log statements:

I'm using sed to replace "console" with "//console" before launching the pressor:

sed -e "s/console/\/\/console/g" originalWithConsoleStatements.js > noConsoleStatements.js

This statement sits inside a shell script which then launches the pressor.

本文标签: javascriptTelling YUI compressor to remove specific noncommented codeStack Overflow