An open API service indexing awesome lists of open source software.

https://github.com/hxfdarling/mp-img-loader


https://github.com/hxfdarling/mp-img-loader

Last synced: 4 months ago
JSON representation

Awesome Lists containing this project

README

        





min programe image Loader


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


Install

```bash
npm install --save-dev mp-imageloader
```

Usage

The `mp-imageloader` works like the [`file-loader`](https://github.com/webpack-contrib/file-loader), but can return a DataURL if the file is smaller than a byte limit.

```js
import img from './image.png';
```

**webpack.config.js**

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

Options

| Name | Type | Default | Description |
| :-------------------------: | :--------: | :-----------: | :------------------------------------------------------------------------------- |
| **[`mimetype`](#mimetype)** | `{String}` | `extname` | Specify MIME type for the file (Otherwise it's inferred from the file extension) |
| **[`fallback`](#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**

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

### `fallback`

**webpack.config.js**

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