Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
feat: add fallback option (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
evilebottnawi authored and michael-ciniawsky committed Sep 14, 2017
1 parent f3f5fce commit 636ebed
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
16 changes: 15 additions & 1 deletion README.md
Expand Up @@ -56,10 +56,12 @@ module.exports = {
|:--:|:--:|:-----:|:----------|
|**`limit`**|`{Number}`|`undefined`|Byte limit to inline files as Data URL|
|**`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)|

### `limit`

If the file is greater than the limit (in bytes) the [`file-loader`](https://github.com/webpack-contrib/file-loader) is used and all query parameters are passed to it.
If the file is greater than the limit (in bytes) the [`file-loader`](https://github.com/webpack-contrib/file-loader) is used by default and all query parameters are passed to it.
You can use other loader using `fallback` option.

The limit can be specified via loader options and defaults to no limit.

Expand Down Expand Up @@ -87,6 +89,18 @@ Set the MIME type for the file. If unspecified the file extensions will be used
}
```

### `fallback`

**webpack.config.js**
```js
{
loader: 'url-loader',
options: {
fallback: 'responsive-loader'
}
}
```

<h2 align="center">Maintainers</h2>

<table>
Expand Down
5 changes: 3 additions & 2 deletions index.js
Expand Up @@ -31,9 +31,10 @@ module.exports = function(content) {
return "module.exports = " + JSON.stringify("data:" + (mimetype ? mimetype + ";" : "") + "base64," + content.toString("base64"));
}

var fileLoader = require("file-loader");
var fallback = options.fallback || "file-loader";
var fallbackLoader = require(fallback);

return fileLoader.call(this, content);
return fallbackLoader.call(this, content);
}

module.exports.raw = true;

0 comments on commit 636ebed

Please sign in to comment.