Skip to content

Commit 7cc1472

Browse files
authored
Merge pull request #2667 from modernweb-dev/fix/output-assets
fix: output assets
2 parents 678ea92 + a1f0979 commit 7cc1472

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

.changeset/clean-peaches-develop.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@web/rollup-plugin-html": patch
3+
---
4+
5+
fix: output assets locations

packages/rollup-plugin-html/src/output/emitAssets.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export async function emitAssets(
104104
if (!emittedExternalAssets.has(assetLocation)) {
105105
const fontFileRef = this.emitFile({
106106
type: 'asset',
107-
name: path.basename(filePath),
107+
name: path.join('assets', path.basename(filePath)),
108108
source: assetContent,
109109
});
110110
const emittedFontFilePath = path.basename(this.getFileName(fontFileRef));

packages/rollup-plugin-html/test/rollup-plugin-html.test.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1066,9 +1066,9 @@ describe('rollup-plugin-html', () => {
10661066
const bundle = await rollup(config);
10671067
const { output } = await bundle.generate(outputConfig);
10681068

1069-
const fontNormal = output.find(o => o.name === 'font-normal.woff2');
1070-
const fontBold = output.find(o => o.name === 'font-normal.woff2');
1071-
const style = output.find(o => o.name === 'styles-with-fonts.css');
1069+
const fontNormal = output.find(o => o.name?.endsWith('font-normal.woff2'));
1070+
const fontBold = output.find(o => o.name?.endsWith('font-normal.woff2'));
1071+
const style = output.find(o => o.name?.endsWith('styles-with-fonts.css'));
10721072
// It has emitted the font
10731073
expect(fontBold).to.exist;
10741074
expect(fontNormal).to.exist;
@@ -1106,8 +1106,8 @@ describe('rollup-plugin-html', () => {
11061106
const bundle = await rollup(config);
11071107
const { output } = await bundle.generate(outputConfig);
11081108

1109-
const font = output.find(o => o.name === 'font-normal.woff2');
1110-
const style = output.find(o => o.name === 'node_modules-styles-with-fonts.css');
1109+
const font = output.find(o => o.name?.endsWith('font-normal.woff2'));
1110+
const style = output.find(o => o.name?.endsWith('node_modules-styles-with-fonts.css'));
11111111

11121112
// It has emitted the font
11131113
expect(font).to.exist;
@@ -1146,7 +1146,7 @@ describe('rollup-plugin-html', () => {
11461146
const bundle = await rollup(config);
11471147
const { output } = await bundle.generate(outputConfig);
11481148

1149-
const fonts = output.filter(o => o.name === 'font-normal.woff2');
1149+
const fonts = output.filter(o => o.name?.endsWith('font-normal.woff2'));
11501150
expect(fonts.length).to.equal(1);
11511151
});
11521152

@@ -1174,13 +1174,13 @@ describe('rollup-plugin-html', () => {
11741174
const bundle = await rollup(config);
11751175
const { output } = await bundle.generate(outputConfig);
11761176

1177-
expect(output.find(o => o.name === 'star.avif')).to.exist;
1178-
expect(output.find(o => o.name === 'star.gif')).to.exist;
1179-
expect(output.find(o => o.name === 'star.jpeg')).to.exist;
1180-
expect(output.find(o => o.name === 'star.jpg')).to.exist;
1181-
expect(output.find(o => o.name === 'star.png')).to.exist;
1182-
expect(output.find(o => o.name === 'star.svg')).to.exist;
1183-
expect(output.find(o => o.name === 'star.webp')).to.exist;
1177+
expect(output.find(o => o.name?.endsWith('star.avif'))).to.exist;
1178+
expect(output.find(o => o.name?.endsWith('star.gif'))).to.exist;
1179+
expect(output.find(o => o.name?.endsWith('star.jpeg'))).to.exist;
1180+
expect(output.find(o => o.name?.endsWith('star.jpg'))).to.exist;
1181+
expect(output.find(o => o.name?.endsWith('star.png'))).to.exist;
1182+
expect(output.find(o => o.name?.endsWith('star.svg'))).to.exist;
1183+
expect(output.find(o => o.name?.endsWith('star.webp'))).to.exist;
11841184

11851185
const rewrittenCss = (output.find(o => o.name === 'styles.css') as OutputAsset).source
11861186
.toString()

0 commit comments

Comments
 (0)