webstorm安装代码压缩插件

webstorm安装代码压缩插件

2019.3版本之前

  1. 使用YUI compressor进行代码压缩,前往 https://github.com/yui/yuicompressor/releases 下载最新版
  2. 快捷键调出settiongs :Ctrl + Alt + S
  3. 找到Tools --> File Watchers --> Add,在弹出的Choose Template列表中配置compressor CSS 和 YUI compressor JS。

2019.3版本之后

  1. 快捷键调出settiongs :Ctrl + Alt + S
  2. 找到Tools --> File Watchers --> Add,会发现Choose Template列表中没有 YUI compressor CSS 和 YUI compressor JS。
  3. 因此不能在使用YUI compressor进行代码的压缩,只能使用UglifyJs进行压缩

通用

  1. 执行cmd 命令下执行java -jar E://yuicompressor-2.4.8.jar D://test/test.js -o 'D://test/test.min.js' --charset utf-8 --type js 即刻完成单个文件的压缩
  2. 官网文档 https://github.com/yui/yuicompressor 有详细的各个参数解释,自己去试。
  3. 批量删除可看如下代码,结合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")){
                // 如果本身是min的直接排除
                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;

                // 如果已经包含min文件就排除
                if (minList.contains(resultName)) {
                    continue;
                }
                Process exec = runtime.exec("cmd.exe /c  " + cmd);
                // 0为正常,1为异常
                int exitValue = exec.waitFor();
                exec.destroy();
                if (exitValue == 0) {
                    file.delete();
                }
            }
        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值