最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论