yosef-tinypng-webpack-plugin

2.0.5 • Public • Published

tinypng-webpack-plugin

a img compress plugin use with tinyPNG for webpack.

Get TinyPNG key

For Developer

Installation

yarn add yosef-tinypng-webpack-plugin

or

npm install yosef-tinypng-webpack-plugin --save-dev

Example Webpack Config

var tinyPngWebpackPlugin = require('yosef-tinypng-webpack-plugin');

    //in your webpack plugins array
    module.exports = {
      plugins: [
          new tinyPngWebpackPlugin({
              key:"your tinyPNG key",
              cacheDir: path.resolve(__dirname, 'src/assets/cache'),
              root: path.resolve(__dirname, 'src')
          })
      ]
    }

Usage

new tinyPngWebpackPlugin({
    key:"your tinyPNG key", //required(string, 'your key')
    ext: ['png', 'jpeg', 'jpg'],//optional(img ext name)
    proxy:'http://user:pass@192.168.0.1:8080',// optional(If you are from China and can use the shadowsocks(vpn), the default proxy will be 'http:127.0.0.1:1080')
    cacheDir: path.resolve(__dirname, 'src/assets/cache'), // optional
    init: false // optional(cache the current img if it's no need for compressing.)
})

Options Description

  • key: Required, tinyPNG key.
  • cacheDir: Required, the plugin will create a json file to include all the compressed img file.
  • root: Required, the folder's path including all the source img.
  • init: not Required
    At first, this options should be set true if you think all the imgs at present are with no need to compress. Just run the 'yarn serve'(or other command) to init all the imgs' cache. Then, this options should be deleted or set false.
  • ext: not Required, img's ext to be compress.
  • proxy:not Required, a http proxy to improve the network environment.eg:http://127.0.0.1:1080.

Defaults Options

    {
        key:'',
        ext: ['png', 'jpeg', 'jpg'],
        proxy:'',
        cacheDir: path.resolve(__dirname, 'map'),
        init: false
    }

License

http://www.opensource.org/licenses/mit-license.php

Package Sidebar

Install

npm i yosef-tinypng-webpack-plugin

Weekly Downloads

0

Version

2.0.5

License

ISC

Unpacked Size

14.3 kB

Total Files

10

Last publish

Collaborators

  • yjiayou