Skip to content
Open
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
5 changes: 5 additions & 0 deletions .changeset/wise-pillows-develop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@web/rollup-plugin-html': minor
---

Include video and source HTML elements as assets in @web/rollup-plugin-html
16 changes: 16 additions & 0 deletions packages/rollup-plugin-html/src/assets/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') ?? '';
Expand Down Expand Up @@ -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':
Expand All @@ -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';
}
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
8 changes: 7 additions & 1 deletion packages/rollup-plugin-html/test/rollup-plugin-html.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,9 @@ describe('rollup-plugin-html', () => {
</head>
<body>
<img src="./image-c.png" />
<video poster="./image-d.png">
<source src="./video.mp4" type="video/mp4"/>
</video>
<div>
<img src="./image-b.svg" />
</div>
Expand All @@ -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',
Expand All @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

console?

Copy link
Contributor Author

@jorenbroekema jorenbroekema Nov 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah just for debugging purposes, this test is failing in a very strange way, suddenly it cannot find the image-c asset as soon as I add image-d (poster attr for video). And I have no idea why 😭 I tried to play around with it and change stuff around but this bug keeps happening.

}
Expand Down