Giter Site home page Giter Site logo

js-banana / image-minify-cl Goto Github PK

View Code? Open in Web Editor NEW
7.0 2.0 0.0 1.43 MB

Minify images:jpg、png

Home Page: https://www.npmjs.com/package/image-minify-cli

License: MIT License

JavaScript 96.47% Shell 3.53%
cli minify image png jpg pngquant nodejs

image-minify-cl's Introduction

image-minify-cli

stars version downloads author logo

鸣谢

本项目参考了这几个库及实现思路 ,并以此为核心对功能进行了包装处理,以匹配自身业务需求。

✨ 描述

image-minify-cli可按照图片目录结构压缩输出相同结构。

// 列如这种结构
// 最终输出目录也会是这种结构

// ——src
//   |——assets
//     |——logo.png
//     |——avatar
//        |——me.jpg

📦 安装

yarn add image-minify-cli -D
# or
npm install image-minify-cli -D

🚀 使用

配置

  • 可开启(log:true)在压缩完成后是否生成日志imagemin.log方便查看。

  • 默认配置

    • 支持图片格式:.{jpg,JPG,jpeg,JPEG,png}
    • jpg压缩插件:imagemin-jpegtran
    • png压缩插件:imagemin-pngquant
    • 文件入口:当前目录下的 ./src/assets
    • 文件出口:同入口(压缩完成后直接替换源文件)

使用方式

一.以插件形式使用

  1. 根目录下创建 imagemin.js 文件

    const imagemin = require("image-minify-cli")
    imagemin({ 
      quality: [0.3, 0.5], 
      input: "./src/asstes", 
      output: "./src" 
    })
  2. 执行脚本

    node imagemin.js

二.命令行使用

该功能需要全局安装,推荐先使用第一种方式

# 1. 查看版本
imagemin -v
# 2. 查看版本
# 注意空格,编译结果为 [0.3,0.5] 
imagemin --quality 0.3 0.5 # --quality 可简写为 -q
# 3. 图片入口路径
# 注意路径写法
imagemin --input ./src/assets # --input 可简写为 -i
# 4. 图片入口路径。
# 图片出口路径
imagemin --output ./src/assets # --output 可简写为 -o
# 开始压缩
imagemin start

✅ Todo

  • 自定义配置
  • 命令行动态传参
  • webpack插件plugin

👀 更新日志

  • 2021.06.15:自定义配置、命令行动态传参

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.