jEdit宏,用于使用YUI compressor压缩.js
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jEdit宏,用于使用YUI compressor压缩.js相关的知识,希望对你有一定的参考价值。
*language: beanshell*be sure to adapt your YUICompressor path
/* * compress.bsh - a BeanShell macro script for the * jEdit text editor - compresses js files and saves as <name>-compressed.js * * Copyright (C) 2010 Patrik Plihal * patrik.plihal gmail com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * */ /* Be sure to adapt 'myPathToYUICompressor' */ void compress(){ if(buffer.isNewFile()) buffer.saveAs(view, true); else buffer.save(view, buffer.getPath()); mode = buffer.getMode().getName(); path = buffer.getPath(); if(os.indexOf("Windows") != -1) path = """ + path + """; newpath = buffer.getPath(); newpath = newpath.replace(".js", "-compressed.js"); myPathToYUICompressor = ""E:\lib\yuicompressor-2.4.2.jar""; runInSystemShell(view,"java -jar " + myPathToYUICompressor + " " + path + " -o " + newpath); /* I want my .js head comments also in my -compress.js */ compressed_comment = ""; for(int i=0;i<8;i++){ //ajust this for amount of comment lines compressed_comment = compressed_comment + buffer.getLineText(i) + ls; } //wait for YUI Compressor waitForConsole(view); StringBuilder contents = new StringBuilder(); try { //read try { while (( line = input.readLine()) != null){ contents.append(line); } } finally { input.close(); } //modify (prepend) compressed = compressed_comment + ls + contents.toString(); //write try { out.write(compressed); } finally { out.close(); } } ex.printStackTrace(); } } else { Macros.error(view, "The current file does not appear to be a javascript."); } } compress();
以上是关于jEdit宏,用于使用YUI compressor压缩.js的主要内容,如果未能解决你的问题,请参考以下文章
JS代码压缩使用YUI Compressor对js文件进行压缩处理
使用 maven、spring、freemarker 等帮助设置 YUI Compressor 以适应不同的环境(测试/开发/生产)