docusaurus/packages/lqip-loader
Sébastien Lorber 7b1b89041f
chore: release Docusaurus v3.1 (#9705)
Co-authored-by: Joshua Chen <sidachen2003@gmail.com>
Co-authored-by: sebastienlorber <lorber.sebastien@gmail.com>
Co-authored-by: Sébastien Lorber <slorber@users.noreply.github.com>
Co-authored-by: Ivan Mar (sOkam!) <7308253+heysokam@users.noreply.github.com>
Co-authored-by: c0h1b4 <dwidman@gmail.com>
Co-authored-by: Janessa Garrow <janessa.garrow@gmail.com>
Co-authored-by: ozaki <29860391+OzakIOne@users.noreply.github.com>
Co-authored-by: axmmisaka <6500159+axmmisaka@users.noreply.github.com>
Co-authored-by: Tatsunori Uchino <tats.u@live.jp>
Co-authored-by: Simen Bekkhus <sbekkhus91@gmail.com>
fix(i18n): complete translations for theme-common.json Brazilian Portuguese (pt-BR) (#9477)
fix(content-blog): add baseUrl for author.image_url (#9581)
fix(type-aliases): add `title` prop for imported inline SVG React components (#9612)
fix(utils): Markdown link replacement with <> but no spaces (#9617)
fix(live-codeblock): stabilize react-live transformCode callback, fix editor/preview desync (#9631)
fix(cli): output help when no conventional config + no subcommand (#9648)
fix CI job (#9604)
fix Lint Autofix workflow (#9632)
fix(pwa-plugin): upgrade workbox (#9668)
fix(create-docusaurus): fix init template code blocks, and little improvements (#9696)
fix(theme): allow empty code blocks and live playgrounds (#9704)
2024-01-05 19:46:35 +01:00
..
src refactor: fix more type-aware linting errors (#7479) 2022-05-24 19:19:24 +08:00
.npmignore misc: make copyUntypedFiles work for watch mode (#7445) 2022-05-18 19:18:32 +08:00
package.json chore: release Docusaurus v3.1 (#9705) 2024-01-05 19:46:35 +01:00
README.md chore: upgrade dependencies (#6991) 2022-03-25 10:47:08 +08:00
tsconfig.json chore: upgrade to TS 4.7, compile with NodeNext (#7586) 2022-06-15 19:15:11 +02:00

@docusaurus/lqip-loader

Low Quality Image Placeholders (LQIP) loader for webpack.

Installation

npm install --save-dev @docusaurus/lqip-loader

Example

Generating Base64 for a jpeg image imported in your JS bundle:

The large image file will be emitted & only 400byte of Base64 (if set to true in the loader options) will be bundled.

webpack.config.js

{
  // OPTION A: default file-loader fallback
  test: /\.jpe?g$/,
  loaders: [
    {
      loader: '@docusaurus/lqip-loader',
      options: {
        path: '/media', // your image going to be in media folder in the output dir
        name: '[name].[ext]', // you can use [contenthash].[ext] too if you wish,
      }
    }
  ]

  // OPTION B: Chained with your own url-loader or file-loader
  test: /\.(png|jpe?g)$/,
  loaders: [
    '@docusaurus/lqip-loader',
    {
      loader: 'url-loader',
      options: {
        limit: 8000
      }
    }
  ]
}

your-app-module.js

import banner from './images/banner.jpg';

console.log(banner.preSrc);
// outputs: "data:image/jpeg;base64,/9j/2wBDAAYEBQYFBAYGBQYHBwYIChAKCgkJChQODwwQFxQYGBcUFhY....

console.log(banner.src); // that's the original image URL to load later!

Important note

To save memory and improve GPU performance, browsers (including Chrome started from 61.0.3163.38) will now render a slightly more crisp or pixelated Base64 encoded images. If you want the blur to be very intense (smooth), here's a fix!

img {
  filter: blur(25px);
}

More history about the issue can be found here and here.

Credits

This package has been imported from @endiliey/lqip-loader which was a fork of the original lqip-loader created exclusively for Docusaurus.