Coder Social home page Coder Social logo

webp-convert-loader's Introduction

webp-convert-loader

A webpack loader that can convert small images into base64 format and generate new webp images with the hash of the source file name. It also preserves the source image.

Features

  • In development mode, a webp image with the same name will be generated in the cache.
  • Supports passing the limit parameter, which limits images under 10k to be converted to base64, while images above that size will be generated as webp images with the same name.

Install

npm install --save-dev webp-convert-loader

Usage

  • webpack / vue-cli2.0 configure as follows:
{
  test: /\.(png|jpe?g)(\?.*)?$/,
  use: [{
    loader: "webp-convert-loader",
    options: {
      limit: 8192,
      quality: 90,
      name: 'static/img/[name].[hash:8].[ext]'
    }
  }]
}
  • vue-cli3.0 configure as follows:
module.exports = {
  chainWebpack: config => {
    const imageRule = config.module.rule('images')
    imageRule.uses.clear()
    config.module.rule('webp')
      .test(/\.(jpe?g|png)$/i)
      .use('webp-convert-loader')
      .loader('webp-convert-loader')
      .options({
        limit: 8192,
        quality: 80,
        name: `static/img/[name].[hash:8].[ext]`
      })
      .end()
  }
}

API

limit

Type: string|number
Default: 10240
Converts images under 10k to base64 by default.

quality

Type: string|number
Default: 80
The quality of the webp image generated from png or jpg.

name

Type: string
Default: [hash].[ext]
The filename and relative path of the generated webp image.

Other parameters can refer to imagemin-webp.

webp-convert-loader's People

Contributors

vivian820225 avatar

Watchers

 avatar

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.