自动化 Eclipse“Yui 压缩机...”
Eclipse PDT 在文件的上下文菜单中有这个方便的内置 Yui 压缩机。但是,当构建使用多个此类文件的 Web 应用程序时,每次更新后手动压缩文件会变得很乏味。它甚至不记得哪些文件压缩为哪些文件名,因此您必须再次输入。
是否可以在 Eclipse 中轻松地自动执行此过程,以便您可以单击“构建”或其他内容,所有指定的文件将被压缩到其目标?
Eclipse 中有关 Yui 功能的文档确实存在真空。
我正在使用 Eclipse Indigo 3.7.0 和 PDT 3.0.0.v20110516-11,但自 Galileo 以来,PDT 和 Yui 选项都非常相似
-update-
自动化解决方案,不是 Eclipse 原生的,但接近:
GNU make makefile
%-min.js: %.js ${java} -jar ${compressor} $< -o ${<:.js=-min.js}
Windows 批处理
FOR %f IN (*.js) DO java -jar yuicompressor.jar %f -o 部署\%f
Linux Shellscript
<前><代码>ls -1 *.js | awk '{printf("java -jar yuicompressor.jar %s -o 部署/%s",$1,$1)}' | /bin/shANT 文件
看这里: http://www.ubik-ingenierie.com/ubikwiki/ index.php?title=Minifying_JS/CSS
如何在此处粘贴 html/xml?
另请参阅这个问题。
Eclipse PDT has this handy built-in Yui Compressor in the context menu for files. But when building a webapp that uses multiple such files, it becomes tedious to compress the files manually after each update. It doesn't even remember what files compress to which filenames, so you have to enter that again.
Is it possible to automate this process easily within Eclipse, so you can click on "build" or something and all specified files will be compressed to their targets?
There is really a vacuum concerning documentation about this Yui feature in Eclipse.
I am using Eclipse Indigo 3.7.0 with PDT 3.0.0.v20110516-11, but both PDT and the Yui option have remained pretty similar since Galileo
-update-
Automation solutions, not Eclipse-native but close:
GNU make makefile
%-min.js: %.js ${java} -jar ${compressor} lt; -o ${<:.js=-min.js}
Windows Batch
FOR %f IN (*.js) DO java -jar yuicompressor.jar %f -o deploy\%f
Linux Shellscript
ls -1 *.js | awk '{printf("java -jar yuicompressor.jar %s -o deploy/%s",$1,$1)}' | /bin/sh
ANT file
See here:
http://www.ubik-ingenierie.com/ubikwiki/index.php?title=Minifying_JS/CSS
How do I paste html/xml here?
Also see this question.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,我实际上下载了 jar 并创建了一个 ANT 任务来压缩 CSS 和 JS。我在 Tomcat 上工作,因此它包括上传内容、清理工作/目录等任务。希望有帮助。
Well, I actually downloaded the jar and created an ANT task to to CSS and JS compression. I work on Tomcat, so it includes tasks to upload stuff, clean work/ directory and things like that. Hope it helps.
您还可以使用 Node.js 进行批量缩小。但是,此选项仅适用于 Linux 用户(目前)。
每当某些软件包严重缺乏便利性(Eclipse)或构建器批处理格式太疯狂(ANT)时,就会有人聪明地出现并创造出一些很棒的东西。
在这种情况下,
非常棒。
只是想我会更新这个问题并添加答案。
You can also batch-minify using Node.js. However, this option is only for Linux users (for now).
Every time some software package is horribly lacking a convenience (Eclipse) or a builder batch format is just crazy (ANT), someone clever comes along and creates something awesome.
In this case,
which is awesome.
Just thought I'd update this question and add the answer.
您可以通过批量配置和添加外部工具来选择和“构建”js/css 资源(适用于 Windows 用户)。
这样一来,只需按一个按钮即可缩小。 (它不是运行配置的一部分。)
先决条件:
- 必须安装Java。
- 您必须下载 yuicompressor。 (目前官方下载页面在这里:https://github.com/yui/yuicompressor/releases )
第 1 步:将“yuicompressor”和“minify.bat”(如下所示)添加到您的项目中。
步骤2:配置名为“Minify”的外部工具(转到菜单“运行”->“外部工具”->“外部工具配置”)。
步骤3:选择资源(js/css)或包含它们的目录,然后单击“缩小”。 js/css 文件将部署到同级“min”目录。
(minify.bat)
You can select and "build" js/css resources by configuring and adding an External Tool with a batch (for Windows users).
This makes it possible to minify by just pressing one button. (It is not part of a run configuration.)
Preconditions:
- Java has to be installed.
- You must download yuicompressor. (Currently the official download page is here: https://github.com/yui/yuicompressor/releases )
Step1: Add "yuicompressor" and "minify.bat" (given below) to your project.
Step2: Configure an External Tool named "Minify" (Go to menu Run -> External Tools -> External Tools Configurations).
Step3: Select the resources (js/css) or the directory that contains them, and click "Minify". The js/css files will be deployed to the sibling "min" directory.
(minify.bat)
我想改进megre的答案(https://stackoverflow.com/a/53678752/760777)。他的解决方案有效,但可以改进。不过,这一切都归功于他。
步骤2:将批处理文件的位置更改为${project_loc}\build\yuicompressor.bat。
将批处理文件“yuicompressor.bat”放入项目文件夹的子文件夹“build”中。
或者将批处理文件放在 yuicompressor 的 jar 文件所在的同一文件夹中。在我的例子中,这将是 C:\Program Files (x86)\yuicompressor\yuicompressor.bat
要引用 css 和 js 文件的正确位置,您可以使用不同的变量, $resource_loc、$project_loc 或 $workspace_loc 与 $project_name 。不同版本的 Eclipse 似乎使用不同的变量。
注意:不要忘记使用双引号,以防路径中有空格。
我最终使用了工作区位置和项目名称。
我的Javascript文件位于名为assets/js的文件夹中,我的样式表位于名为assets/css的文件夹中
请参见屏幕截图:
我完全更改了批处理文件:
可能不必说,但要使用缩小的文件,你必须相应地修改 HTML / PHP 文件中的引用。
I would like to improve the answer of megre (https://stackoverflow.com/a/53678752/760777). His solution works, but can be improved. All credits to him though.
In step 2: Change the location of the batch file into ${project_loc}\build\yuicompressor.bat.
Place your batch file "yuicompressor.bat" in a subfolder "build" in your project folder.
Or place the batch file in the same folder the jar file of yuicompressor resides. In my case that would be C:\Program Files (x86)\yuicompressor\yuicompressor.bat
To refer to the right location of your css and js files, you can use different variables, $resource_loc, $project_loc or $workspace_loc with $project_name. Different versions of Eclipse seem to use different variables.
Note: Don't forget to use double quotes, in the case there are spaces in the path.
I ended up using the workspace location combinded with the project name.
My Javascript files are in a folder named assets/js and my stylesheets are in a folder named assets/css
See screenshot:
I changed the batch file completely:
Probably unnecessary to say, but to use the minified files, you have to modify the references in your HTML / PHP files accordingly.