From 091a5fa68271abafed4d40a7fca8570ac6605193 Mon Sep 17 00:00:00 2001 From: evilebottnawi Date: Wed, 13 Sep 2017 20:52:14 +0300 Subject: [PATCH] feat: add `fallback` option --- README.md | 16 +++++++++++++++- index.js | 5 +++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 189f8a2..498390a 100644 --- a/README.md +++ b/README.md @@ -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. @@ -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' + } +} +``` +

Maintainers

diff --git a/index.js b/index.js index 6ee4fa2..8aa4666 100644 --- a/index.js +++ b/index.js @@ -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;