2019.3版本之前
- 使用YUI compressor进行代码压缩,前往 https://github.com/yui/yuicompressor/releases 下载最新版
- 快捷键调出settiongs :Ctrl + Alt + S。
- 找到Tools --> File Watchers --> Add,在弹出的Choose Template列表中配置compressor CSS 和 YUI compressor JS。
2019.3版本之后
- 快捷键调出settiongs :Ctrl + Alt + S。
- 找到Tools --> File Watchers --> Add,会发现Choose Template列表中没有 YUI compressor CSS 和 YUI compressor JS。
- 因此不能在使用YUI compressor进行代码的压缩,只能使用UglifyJs进行压缩
通用
- 执行cmd 命令下执行
java -jar E://yuicompressor-2.4.8.jar D://test/test.js -o 'D://test/test.min.js' --charset utf-8 --type js
即刻完成单个文件的压缩 - 官网文档 https://github.com/yui/yuicompressor 有详细的各个参数解释,自己去试。
批量删除
可看如下代码,结合java程序实现
public static void main(String[] args) throws IOException, InterruptedException {
String cmd = "java -jar E://yuicompressor-2.4.8.jar %s -o '%s' --charset utf-8 --type %s";
Runtime runtime = Runtime.getRuntime();
List<File> files = FileUtil.loopFiles("D://test");
List<String> minList = files.stream().map(File::getName).collect(Collectors.toList());
for (File file : files) {
String path = file.getPath();
String name = file.getName();
String parent = file.getParent();
if ( path.endsWith(".js") || parent.endsWith(".css")){
if (path.endsWith(".min.js") || path.endsWith(".min.css")){
continue;
}
String fileName = name.substring(0,name.lastIndexOf("."));
String suffixName = path.endsWith(".js")?".min.js":".min.css";
String resultName = parent + "/" + fileName +"."+suffixName;
if (minList.contains(resultName)) {
continue;
}
Process exec = runtime.exec("cmd.exe /c " + cmd);
int exitValue = exec.waitFor();
exec.destroy();
if (exitValue == 0) {
file.delete();
}
}
}
}