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

feat: add fallback option (options.fallback) #88

Merged
merged 1 commit into from
Sep 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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;