From 64fda8d317e9b065e12f79cb45f8da86765692b3 Mon Sep 17 00:00:00 2001 From: Scott O'Hara Date: Wed, 27 Oct 2021 17:16:24 +1100 Subject: [PATCH 1/4] docs(readme): clarify that tag is not optional if extending default sources --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 09329e75..c15c14eb 100644 --- a/README.md +++ b/README.md @@ -241,6 +241,8 @@ module.exports = { If the tag name is not specified it will process all the tags. +> ⚠ You must specify the tag name if using `...` to extend the default sources list + > You can use your custom filter to specify html elements to be processed. For example: From 687b4f94cd052641b99f909ce87749fe50e7bc3c Mon Sep 17 00:00:00 2001 From: Scott O'Hara Date: Thu, 28 Oct 2021 08:53:33 +1100 Subject: [PATCH 2/4] docs(readme): add examples for optional tag --- README.md | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c15c14eb..27dc3011 100644 --- a/README.md +++ b/README.md @@ -241,7 +241,68 @@ module.exports = { If the tag name is not specified it will process all the tags. -> ⚠ You must specify the tag name if using `...` to extend the default sources list +**Note:** source with a `tag` option takes precedence over source without. + +For example, to process `data-src` attributes on _all_ tags, omit the tag name: + +**webpack.config.js** + +```js +module.exports = { + module: { + rules: [ + { + test: /\.html$/i, + loader: "html-loader", + options: { + sources: { + list: [ + { + attribute: "data-src", + type: "src", + }, + ], + }, + }, + }, + ], + }, +}; +``` + +> ⚠ You **must** specify a tag name if using `...` to extend attributes for tags already in the default sources list + +For example, to extend the default source list so that it also processes `data-src` attributes on _all_ tags, you might be tempted to do this: + +```js +module.exports = { + module: { + rules: [ + { + test: /\.html$/i, + loader: "html-loader", + options: { + sources: { + list: [ + // All default supported tags and attributes + "...", + { + attribute: "data-src", + type: "src", + }, + ], + }, + }, + }, + ], + }, +}; +``` + +However this will only process `data-src` attributes on tags that _aren't in the default list_: + +- `

` will be processed, as `p` is not in the default sources list +- `` won't be processed, as `img` is already in the default sources list > You can use your custom filter to specify html elements to be processed. @@ -322,8 +383,6 @@ module.exports = { }; ``` -**Note:** source with a `tag` option takes precedence over source without. - Filter can be used to disable default sources. For example: From 03a81db0096ac09f0f6078e0111f6738a2a51cf0 Mon Sep 17 00:00:00 2001 From: Scott O'Hara Date: Sat, 30 Oct 2021 23:59:50 +1100 Subject: [PATCH 3/4] docs(readme): revert earlier changes --- README.md | 65 ++----------------------------------------------------- 1 file changed, 2 insertions(+), 63 deletions(-) diff --git a/README.md b/README.md index 27dc3011..09329e75 100644 --- a/README.md +++ b/README.md @@ -241,69 +241,6 @@ module.exports = { If the tag name is not specified it will process all the tags. -**Note:** source with a `tag` option takes precedence over source without. - -For example, to process `data-src` attributes on _all_ tags, omit the tag name: - -**webpack.config.js** - -```js -module.exports = { - module: { - rules: [ - { - test: /\.html$/i, - loader: "html-loader", - options: { - sources: { - list: [ - { - attribute: "data-src", - type: "src", - }, - ], - }, - }, - }, - ], - }, -}; -``` - -> ⚠ You **must** specify a tag name if using `...` to extend attributes for tags already in the default sources list - -For example, to extend the default source list so that it also processes `data-src` attributes on _all_ tags, you might be tempted to do this: - -```js -module.exports = { - module: { - rules: [ - { - test: /\.html$/i, - loader: "html-loader", - options: { - sources: { - list: [ - // All default supported tags and attributes - "...", - { - attribute: "data-src", - type: "src", - }, - ], - }, - }, - }, - ], - }, -}; -``` - -However this will only process `data-src` attributes on tags that _aren't in the default list_: - -- `

` will be processed, as `p` is not in the default sources list -- `` won't be processed, as `img` is already in the default sources list - > You can use your custom filter to specify html elements to be processed. For example: @@ -383,6 +320,8 @@ module.exports = { }; ``` +**Note:** source with a `tag` option takes precedence over source without. + Filter can be used to disable default sources. For example: From 7536bfcb6938dfe938756f7a1c88ee2f9a746fc4 Mon Sep 17 00:00:00 2001 From: Scott O'Hara Date: Sun, 31 Oct 2021 00:06:39 +1100 Subject: [PATCH 4/4] fix: merge attributes without tag and attributes with tag --- src/plugins/sources-plugin.js | 7 +- .../__snapshots__/sources-option.test.js.snap | 519 ++++++++++++++++++ test/sources-option.test.js | 22 + 3 files changed, 545 insertions(+), 3 deletions(-) diff --git a/src/plugins/sources-plugin.js b/src/plugins/sources-plugin.js index 77480eb9..1f39c044 100644 --- a/src/plugins/sources-plugin.js +++ b/src/plugins/sources-plugin.js @@ -41,9 +41,10 @@ export default (options) => name = attribute.prefix ? `${attribute.prefix}:${name}` : name; - const handlers = - options.sources.list.get(tagName.toLowerCase()) || - options.sources.list.get("*"); + const handlers = new Map([ + ...(options.sources.list.get("*") || new Map()), + ...(options.sources.list.get(tagName.toLowerCase()) || new Map()), + ]); if (!handlers) { return; diff --git a/test/__snapshots__/sources-option.test.js.snap b/test/__snapshots__/sources-option.test.js.snap index a93b65d4..bd4b3d41 100644 --- a/test/__snapshots__/sources-option.test.js.snap +++ b/test/__snapshots__/sources-option.test.js.snap @@ -3307,6 +3307,525 @@ ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4 exports[`'sources' option should not handle sources with a "boolean" notation equals "false": warnings 1`] = `Array []`; +exports[`'sources' option should process attributes specific to a tag and attributes for any tag: errors 1`] = `Array []`; + +exports[`'sources' option should process attributes specific to a tag and attributes for any tag: module 1`] = ` +"// Imports +import ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___ from \\"../../src/runtime/getUrl.js\\"; +var ___HTML_LOADER_IMPORT_0___ = new URL(\\"./image.png\\", import.meta.url); +var ___HTML_LOADER_IMPORT_1___ = new URL(\\"/image.png\\", import.meta.url); +var ___HTML_LOADER_IMPORT_2___ = new URL(\\"aliasImg\\", import.meta.url); +var ___HTML_LOADER_IMPORT_3___ = new URL(\\"./script.file.js\\", import.meta.url); +var ___HTML_LOADER_IMPORT_4___ = new URL(\\"./icons.svg\\", import.meta.url); +var ___HTML_LOADER_IMPORT_5___ = new URL(\\"./image.png?foo=bar,baz\\", import.meta.url); +var ___HTML_LOADER_IMPORT_6___ = new URL(\\"./image.png?bar=baz,foo\\", import.meta.url); +var ___HTML_LOADER_IMPORT_7___ = new URL(\\"./example.ogg\\", import.meta.url); +var ___HTML_LOADER_IMPORT_8___ = new URL(\\"./example.pdf\\", import.meta.url); +var ___HTML_LOADER_IMPORT_9___ = new URL(\\"./example.vtt\\", import.meta.url); +var ___HTML_LOADER_IMPORT_10___ = new URL(\\"./style.file.css\\", import.meta.url); +var ___HTML_LOADER_IMPORT_11___ = new URL(\\"./image image.png\\", import.meta.url); +var ___HTML_LOADER_IMPORT_12___ = new URL(\\"./module.file.js\\", import.meta.url); +var ___HTML_LOADER_IMPORT_13___ = new URL(\\"./fallback.file.js\\", import.meta.url); +var ___HTML_LOADER_IMPORT_14___ = new URL(\\"aliasImageWithSpace\\", import.meta.url); +var ___HTML_LOADER_IMPORT_15___ = new URL(\\"./webpack.svg\\", import.meta.url); +var ___HTML_LOADER_IMPORT_16___ = new URL(\\"./pixel.png?url\\", import.meta.url); +var ___HTML_LOADER_IMPORT_17___ = new URL(\\"./site.webmanifest\\", import.meta.url); +var ___HTML_LOADER_IMPORT_18___ = new URL(\\"./browserconfig.xml\\", import.meta.url); +var ___HTML_LOADER_IMPORT_19___ = new URL(\\"./favicon.ico\\", import.meta.url); +var ___HTML_LOADER_IMPORT_20___ = new URL(\\"./sound.mp3\\", import.meta.url); +var ___HTML_LOADER_IMPORT_21___ = new URL(\\"./video.mp4\\", import.meta.url); +var ___HTML_LOADER_IMPORT_22___ = new URL(\\"./nested/image3.png\\", import.meta.url); +var ___HTML_LOADER_IMPORT_23___ = new URL(\\"/nested/image3.png\\", import.meta.url); +// Module +var ___HTML_LOADER_REPLACEMENT_0___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___); +var ___HTML_LOADER_REPLACEMENT_1___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___, { maybeNeedQuotes: true }); +var ___HTML_LOADER_REPLACEMENT_2___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_1___); +var ___HTML_LOADER_REPLACEMENT_3___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_2___); +var ___HTML_LOADER_REPLACEMENT_4___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_3___); +var ___HTML_LOADER_REPLACEMENT_5___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_4___, { hash: \\"#icon-chevron-with-circle-up\\" }); +var ___HTML_LOADER_REPLACEMENT_6___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_5___); +var ___HTML_LOADER_REPLACEMENT_7___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_6___); +var ___HTML_LOADER_REPLACEMENT_8___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_7___); +var ___HTML_LOADER_REPLACEMENT_9___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_8___); +var ___HTML_LOADER_REPLACEMENT_10___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_9___); +var ___HTML_LOADER_REPLACEMENT_11___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_10___); +var ___HTML_LOADER_REPLACEMENT_12___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_11___); +var ___HTML_LOADER_REPLACEMENT_13___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_12___); +var ___HTML_LOADER_REPLACEMENT_14___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_13___); +var ___HTML_LOADER_REPLACEMENT_15___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_14___, { maybeNeedQuotes: true }); +var ___HTML_LOADER_REPLACEMENT_16___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_14___); +var ___HTML_LOADER_REPLACEMENT_17___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___, { hash: \\"#hash\\" }); +var ___HTML_LOADER_REPLACEMENT_18___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___, { hash: \\"#hash\\", maybeNeedQuotes: true }); +var ___HTML_LOADER_REPLACEMENT_19___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___, { hash: \\"#\\", maybeNeedQuotes: true }); +var ___HTML_LOADER_REPLACEMENT_20___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___, { hash: \\"#foo\\" }); +var ___HTML_LOADER_REPLACEMENT_21___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___, { hash: \\"#bar\\" }); +var ___HTML_LOADER_REPLACEMENT_22___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_0___, { hash: \\"#baz\\" }); +var ___HTML_LOADER_REPLACEMENT_23___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_14___, { hash: \\"#hash\\", maybeNeedQuotes: true }); +var ___HTML_LOADER_REPLACEMENT_24___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_15___); +var ___HTML_LOADER_REPLACEMENT_25___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_16___); +var ___HTML_LOADER_REPLACEMENT_26___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_17___); +var ___HTML_LOADER_REPLACEMENT_27___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_18___); +var ___HTML_LOADER_REPLACEMENT_28___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_19___); +var ___HTML_LOADER_REPLACEMENT_29___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_20___); +var ___HTML_LOADER_REPLACEMENT_30___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_21___); +var ___HTML_LOADER_REPLACEMENT_31___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_22___); +var ___HTML_LOADER_REPLACEMENT_32___ = ___HTML_LOADER_GET_SOURCE_FROM_IMPORT___(___HTML_LOADER_IMPORT_23___); +var code = \\"\\\\n\\\\n

My First Heading

\\\\n

My first paragraph.

\\\\n

An Unordered HTML List

\\\\n\\\\n\\\\n\\\\n

An Ordered HTML List

\\\\n\\\\n
    \\\\n
  1. Coffee
  2. \\\\n
  3. Tea
  4. \\\\n
  5. Milk
  6. \\\\n
\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n
Foo
\\\\n\\\\n\\\\n
BAR
\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\n\\\\n \\\\n \\\\n \\\\\\"Flowers\\\\\\"\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\\\"Smiley\\\\n\\\\n
\\\\n First name:
\\\\n \\\\n
\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\nT ex t \\\\n\\\\n
\\\\n\\\\n]]>\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\nlink text\\\\n\\\\nCall me\\\\n\\\\n-->\\\\n-->\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n
\\\\n
\\\\n\\\\n<div id = "character">\\\\n© 2007\\\\nor\\\\n© 2007\\\\n\\\\n
\\\\n\\\\n\\\\\\"Red\\\\n
\\\\n Written by Jon Doe.
\\\\n Visit us at:
\\\\n Example.com
\\\\n Box 564, Disneyland
\\\\n USA\\\\n
\\\\nlink\\\\nStart Chat\\\\nStart Chat\\\\nStart Chat\\\\n\\\\n\\\\n\\\\n\\\\\\"Elva\\\\n\\\\\\"Elva\\\\n\\\\n\\\\\\"Elva\\\\n\\\\\\"Test\\\\\\"\\\\n\\\\n\\\\n\\\\n Test \\\\n\\\\ntest\\\\ntest\\\\ntest\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n

Text

\\\\n

Text

\\\\n

Text

\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\\\"Elva\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\\\"Elva\\\\n\\\\\\"test\\\\\\"/\\\\n\\\\\\"test\\\\\\"\\\\n\\\\\\"test\\\\\\"\\\\n\\\\\\"test\\\\\\"/\\\\n\\\\\\"test\\\\\\"/\\\\n\\\\n\\\\n\\\\\\"Elva\\\\n\\\\n\\\\n\\\\n\\\\n \\\\n\\\\n\\\\n\\\\n \\\\n\\\\n\\\\n\\\\n \\\\n\\\\n\\\\n\\\\n \\\\n\\\\n\\\\nfoo bar\\\\n\\\\nText\\\\nText\\\\n\\\\n\\\\n\\\\n
\\\\n\\\\nVisit our HTML tutorial\\\\nVisit our HTML tutorial\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n
text
\\\\n
text
\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\\\"\\\\\\"\\\\n\\\\n\\\\\\"\\\\\\"\\\\n\\\\n\\\\\\"multi\\\\nline\\\\nalt\\\\\\"\\\\n\\\\n\\\\\\"Red\\\\n\\\\n\\\\\\" alt=\\\\\\"<%= name %>\\\\\\" src=\\\\\\"<%= imgsrc %>\\\\\\" />\\\\n\\\\n\\\\n \\\\n\\\\n\\\\n \\\\n\\\\n\\\\n \\\\n\\\\n\\\\n \\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n\\\\n
\\\\n \\\\n
\\"; +// Exports +export default code;" +`; + +exports[`'sources' option should process attributes specific to a tag and attributes for any tag: result 1`] = ` +" + +

My First Heading

+

My first paragraph.

+

An Unordered HTML List

+ +
    +
  • Coffee
  • +
  • Tea
  • +
  • Milk
  • +
+ +

An Ordered HTML List

+ +
    +
  1. Coffee
  2. +
  3. Tea
  4. +
  5. Milk
  6. +
+ + + + + +
Foo
+ + +
BAR
+ + + + + + + + + + + + + + + + + + + + + + + + + + +\\"Elva +\\"Elva +\\"Elva +\\"Elva +\\"Elva +\\"Elva +\\"Elva +\\"Elva +\\"Elva +\\"Elva +\\"Elva +\\"Elva +\\"Elva + + + + + \\"Flowers\\" + + + + + + + + +\\"Smiley + +
+ First name:
+ +
+ + + + + + + + + + + + + +T ex t + +
+ +]]> + + + + + + + + + + + + + + + + + + + + + + + +link text + +Call me + +--> +--> + + + + + +
+
+ +<div id = "character"> +© 2007 +or +© 2007 + +
+ +\\"Red +
+ Written by Jon Doe.
+ Visit us at:
+ Example.com
+ Box 564, Disneyland
+ USA +
+link +Start Chat +Start Chat +Start Chat + + + +\\"Elva +\\"Elva + +\\"Elva +\\"Test\\" + + + + Test + +test +test +test + + + + + +

Text

+

Text

+

Text

+ + + + + + + + + + + + + + + + + + + + +\\"Elva + + + + + + + + + + + +\\"Elva +\\"test\\"/ +\\"test\\" +\\"test\\" +\\"test\\"/ +\\"test\\"/ + + +\\"Elva + + + + + + + + + + + + + + + + + + + +foo bar + +Text +Text + + + +
+ +Visit our HTML tutorial +Visit our HTML tutorial + + + + + +
text
+
text
+ + + + + +\\"\\" + +\\"\\" + +\\"multi + +\\"Red + +\\" alt=\\"<%= name %>\\" src=\\"<%= imgsrc %>\\" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
" +`; + +exports[`'sources' option should process attributes specific to a tag and attributes for any tag: warnings 1`] = `Array []`; + exports[`'sources' option should work and override the "img" tag logic with "...": errors 1`] = `Array []`; exports[`'sources' option should work and override the "img" tag logic with "...": module 1`] = ` diff --git a/test/sources-option.test.js b/test/sources-option.test.js index 8126c62c..5e7456f6 100644 --- a/test/sources-option.test.js +++ b/test/sources-option.test.js @@ -137,6 +137,28 @@ describe("'sources' option", () => { expect(getErrors(stats)).toMatchSnapshot("errors"); }); + it("should process attributes specific to a tag and attributes for any tag", async () => { + const compiler = getCompiler("simple.js", { + sources: { + list: [ + "...", + { + attribute: "data-src", + type: "src", + }, + ], + }, + }); + const stats = await compile(compiler); + + expect(getModuleSource("./simple.html", stats)).toMatchSnapshot("module"); + expect( + execute(readAsset("main.bundle.js", compiler, stats)) + ).toMatchSnapshot("result"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); + }); + it('should handle "webpack-import" and `webpack-partial` tags', async () => { const compiler = getCompiler("webpack-import.js"); const stats = await compile(compiler);