diff --git a/.changeset/wise-pillows-develop.md b/.changeset/wise-pillows-develop.md new file mode 100644 index 000000000..cf000d527 --- /dev/null +++ b/.changeset/wise-pillows-develop.md @@ -0,0 +1,5 @@ +--- +'@web/rollup-plugin-html': minor +--- + +Include video and source HTML elements as assets in @web/rollup-plugin-html diff --git a/packages/rollup-plugin-html/src/assets/utils.ts b/packages/rollup-plugin-html/src/assets/utils.ts index 6c773ba0b..e49ecf7d6 100644 --- a/packages/rollup-plugin-html/src/assets/utils.ts +++ b/packages/rollup-plugin-html/src/assets/utils.ts @@ -13,6 +13,12 @@ function isAsset(node: Node) { case 'img': path = getAttribute(node, 'src') ?? ''; break; + case 'video': + path = getAttribute(node, 'poster') ?? ''; + break; + case 'source': + path = getAttribute(node, 'src') ?? ''; + break; case 'link': if (linkRels.includes(getAttribute(node, 'rel') ?? '')) { path = getAttribute(node, 'href') ?? ''; @@ -46,6 +52,10 @@ export function isHashedAsset(node: Node) { switch (getTagName(node)) { case 'img': return true; + case 'video': + return true; + case 'source': + return true; case 'script': return true; case 'link': @@ -72,6 +82,12 @@ export function getSourceAttribute(node: Node) { case 'link': { return 'href'; } + case 'video': { + return 'poster'; + } + case 'source': { + return 'src'; + } case 'script': { return 'src'; } diff --git a/packages/rollup-plugin-html/test/fixtures/assets/image-d.png b/packages/rollup-plugin-html/test/fixtures/assets/image-d.png new file mode 100644 index 000000000..088d83d6d Binary files /dev/null and b/packages/rollup-plugin-html/test/fixtures/assets/image-d.png differ diff --git a/packages/rollup-plugin-html/test/fixtures/assets/video.mp4 b/packages/rollup-plugin-html/test/fixtures/assets/video.mp4 new file mode 100644 index 000000000..1fc478842 Binary files /dev/null and b/packages/rollup-plugin-html/test/fixtures/assets/video.mp4 differ diff --git a/packages/rollup-plugin-html/test/rollup-plugin-html.test.ts b/packages/rollup-plugin-html/test/rollup-plugin-html.test.ts index d76e022d0..e2a09d4a6 100644 --- a/packages/rollup-plugin-html/test/rollup-plugin-html.test.ts +++ b/packages/rollup-plugin-html/test/rollup-plugin-html.test.ts @@ -628,6 +628,9 @@ describe('rollup-plugin-html', () => { +
@@ -641,7 +644,7 @@ describe('rollup-plugin-html', () => { const bundle = await rollup(config); const { output } = await bundle.generate(outputConfig); - expect(output.length).to.equal(11); + expect(output.length).to.equal(12); const expectedAssets = [ 'image-c.png', 'webmanifest.json', @@ -650,10 +653,13 @@ describe('rollup-plugin-html', () => { 'x.css', 'y.css', 'image-b.svg', + 'image-d.png', + 'video.mp4', ]; for (const name of expectedAssets) { const asset = getAsset(output, name); + console.log(asset, name); expect(asset).to.exist; expect(asset.source).to.exist; }