Code Monkey home page Code Monkey logo

webp-loader's Introduction

webp-loader

Build Status

WebP image loader & converter loader for Webpack.

Install

npm install webp-loader --save-dev

Usage

Here is the example of using webp-loader along with common file-loader:

loaders: [
  {
    test: /\.(jpe?g|png)$/i,
    loaders: [
      'file-loader',
      'webp-loader'
    ]
  }
]

Unfortunately, if you wish to pass an options for internal imagemin-webp you should pass a options in JSON form:

loaders: [
  {
    test: /\.(jpe?g|png)$/i,
    loaders: [
      'file-loader',
      'webp-loader?{quality: 13}'
    ]
  }
]

Normally you don't want to convert all of your images to WebP format, you just want to make alternate versions. You can use multi-loader to achieve it:

loaders: [
  {
    test: /\.(jpe?g|png)$/i,
    loader: multi(
      'file-loader?name=[name].[ext].webp!webp-loader?{quality: 95}'
      'file-loader?name=[name].[ext]',
    )
  },
]

Options

For all possible options please visit "API" section of the official imagemin-webp README.

Inspiration

webp-loader is heavily inspired by tcoopman/image-webpack-loader.

License

MIT

webp-loader's People

Contributors

brandonxiang avatar brunosabot avatar kavu avatar lkinasiewicz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

webp-loader's Issues

Generate both images (jpg/png and webp) with hash.

Hi,

I'm trying to generate alternate versions for my images, which is working fine. However, when I'm trying add hashes , I'm getting a problem.

I'm using part of code from README but adding [hash] placeholder

loaders: [
  {
    test: /\.(jpe?g|png)$/i,
    loader: multi(
      'file-loader?name=[name].[hash].webp!webp-loader?{quality: 95}'
      'file-loader?name=[name].[hash].[ext]',
    )
  },
]

Which is working, but generating different hashes

So output will be:

image.12345.jpg
image.67890.webp

Can I somehow generate img's with same hashes, like this:

image.12345.jpg
image.12345.webp

Thanks

error


ERROR in ./~/vue-loader/lib/template-compiler?{"id":"data-v-f87c58e0"}!./~/vux-loader/src/before-template-compiler-loader.js!./~/vux-loader/src/template-loader.js!./~/vue-loader/lib/selector.js?type=template&index=0!./src/App.vue
Module not found: Error: Can't resolve 'webp' in '/Users/vivo/Documents/vscode_workspace/quick_start/vue/member_mobile'
 @ ./~/vue-loader/lib/template-compiler?{"id":"data-v-f87c58e0"}!./~/vux-loader/src/before-template-compiler-loader.js!./~/vux-loader/src/template-loader.js!./~/vue-loader/lib/selector.js?type=template&index=0!./src/App.vue 4:13-41
 @ ./src/App.vue
 @ ./src/main.js

Is there any update plans?

imagemin is updated in version 7, and drop supporting Node.js 6.
Please let us know if you plan to update.

Build errors on webpack with NextJS

$ next build
Loaded env from /home/ubuntu/repositories/ecommerce/.env
info  - Using external babel configuration from /home/ubuntu/repositories/ecommerce/.babelrc
info  - Creating an optimized production build 
Failed to compile.

./src/assets/images/home/abcde.jpg?webp
Error: /home/ubuntu/repositories/ecommerce/node_modules/cwebp-bin/vendor/cwebp: error while loading shared libraries: libGL.so.1: cannot open shared object file: No such file or directory
    at runMicrotasks (<anonymous>)


> Build error occurred
Error: > Build failed because of webpack errors
    at /home/ubuntu/repositories/ecommerce/node_modules/next/dist/build/index.js:15:918
    at async /home/ubuntu/repositories/ecommerce/node_modules/next/dist/build/tracer.js:1:525
error Command failed with exit code 1.

Testing

It will be good to add TravisCI for testing and show status in README

Query options are ignored in version 0.2.0

When i set

module: {
    rules: [
        {
            test: /\.(png|gif)$/,
            use: [
                {
                    loader: 'url-loader',
                    options: { 'limit': 8192 }
                },
                {
                    loader: 'webp-loader',
                    options: { lossless: true, quality: 90 }
                }
            ]
        }
    ]
}

loader's options are ignored

Peer dependency on webpack-cli?

Why is there a peer dependency on the CLI? It seems pointless, since it does work without it. One can use webpack's Node API, for example.

If it's not needed, we should remove it so we don't clutter the output with misleading warning messages.

warning " > [email protected]" has unmet peer dependency "webpack-cli@*".

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.