javascript - Telling YUI compressor to remove specific non-commented code - Stack Overflow

In my javascript I have some bits of code specifically used for debugging which I don't want to in

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745294211a4621041.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信