From 70370dc369d40bc14958b2c8fce298ab1b78eb8a Mon Sep 17 00:00:00 2001 From: Andrea Puddu Date: Wed, 12 Jul 2017 14:35:50 +0200 Subject: [PATCH] feat: add support for empty tags in `tag:attribute` matching (#129) --- README.md | 14 ++++++++++++++ index.js | 6 +++++- test/loaderTest.js | 7 +++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 49296c47..29ca6783 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,20 @@ By default every local `` is required (`require('./image.pn You can specify which tag-attribute combination should be processed by this loader via the query parameter `attrs`. Pass an array or a space-separated list of `:` combinations. (Default: `attrs=img:src`) +If you use ``, and lots of them make use of a `custom-src` attribute, you don't have to specify each combination `:`: just specify an empty tag like `attrs=:custom-src` and it will match every element. + +```js +{ + test: /\.(html)$/, + use: { + loader: 'html-loader', + options: { + attrs: [':data-src'] + } + } +} +``` + To completely disable tag-attribute processing (for instance, if you're handling image loading on the client side) you can pass in `attrs=false`.

Examples

diff --git a/index.js b/index.js index d575e030..ba1049d2 100644 --- a/index.js +++ b/index.js @@ -39,7 +39,11 @@ module.exports = function(content) { } var root = config.root; var links = attrParse(content, function(tag, attr) { - return attributes.indexOf(tag + ":" + attr) >= 0; + var item = tag + ":" + attr; + var res = attributes.find(function(a) { + return item.indexOf(a) >= 0; + }); + return !!res; }); links.reverse(); var data = {}; diff --git a/test/loaderTest.js b/test/loaderTest.js index 285fdfd6..2546f443 100644 --- a/test/loaderTest.js +++ b/test/loaderTest.js @@ -29,6 +29,13 @@ describe("loader", function() { 'module.exports = "Text