/mp-img-loader

Primary LanguageJavaScriptMIT LicenseMIT

min programe image Loader

Loads files as `base64` encoded URL or upload to cloud

Install

npm install --save-dev mp-imageloader

The mp-imageloader works like the file-loader, but can return a DataURL if the file is smaller than a byte limit.

import img from './image.png';

webpack.config.js

module.exports = {
  module: {
    rules: [
      {
        test: /\.(png|jpg|gif)$/,
        use: [
          {
            loader: 'mp-imageloader',
            options: {},
          },
        ],
      },
    ],
  },
};

Options

Name Type Default Description
mimetype {String} extname Specify MIME type for the file (Otherwise it's inferred from the file extension)
fallback {String} file-loader Specify loader for the file when file is greater than the limit (in bytes)

mimetype

Set the MIME type for the file. If unspecified the file extensions will be used to lookup the MIME type.

webpack.config.js

{
  loader: 'mp-imageloader',
  options: {
    mimetype: 'image/png'
  }
}

fallback

webpack.config.js

{
  loader: 'mp-imageloader',
  options: {
    fallback: 'responsive-loader'
  }
}