Skip to content

Commit ad5288c

Browse files
committed
address bug #1834
1 parent d64f8d6 commit ad5288c

File tree

5 files changed

+56
-2
lines changed

5 files changed

+56
-2
lines changed

β€Žpackages/html/src/index.tsβ€Ž

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ const defaultTemplate = async ({
3434
title,
3535
addScriptsToHead
3636
}: RollupHtmlTemplateOptions) => {
37+
// Only directly <script>-load entry chunks; others are loaded indirectly
3738
let scripts = (files.js || [])
38-
.map(({ fileName }) => {
39+
.filter((file) => file.type === 'chunk' && file.isEntry)
40+
.map((file) => {
3941
const attrs = makeHtmlAttributes(attributes.script);
40-
return `<script src="${publicPath}${fileName}"${attrs}></script>`;
42+
return `<script src="${publicPath}${file.fileName}"${attrs}></script>`;
4143
})
4244
.join('\n');
4345

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
if (Math.random() % 2) {
2+
import('./batman.js');
3+
}

β€Žpackages/html/test/snapshots/test.js.mdβ€Ž

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,46 @@ Generated by [AVA](https://avajs.dev).
327327
},
328328
]
329329

330+
## dynamic_imports_not_loaded
331+
332+
> Snapshot 1
333+
334+
[
335+
{
336+
code: `if (Math.random() % 2) {␊
337+
import('./batman-w40geAFS.js');␊
338+
}␊
339+
`,
340+
fileName: 'catwoman.js',
341+
map: null,
342+
source: undefined,
343+
},
344+
{
345+
code: `␊
346+
`,
347+
fileName: 'batman-w40geAFS.js',
348+
map: null,
349+
source: undefined,
350+
},
351+
{
352+
code: undefined,
353+
fileName: 'index.html',
354+
map: undefined,
355+
source: `␊
356+
<!doctype html>␊
357+
<html lang="en">␊
358+
<head>␊
359+
<meta charset="utf-8">␊
360+
<title>Rollup Bundle</title>␊
361+
␊
362+
</head>␊
363+
<body>␊
364+
<script src="catwoman.js" type="module"></script>␊
365+
</body>␊
366+
</html>`,
367+
},
368+
]
369+
330370
## template
331371

332372
> Snapshot 1
144 Bytes
Binary file not shown.

β€Žpackages/html/test/test.jsβ€Ž

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@ test.serial('imports', async (t) => {
108108
t.snapshot(code);
109109
});
110110

111+
test.serial('dynamic_imports_not_loaded', async (t) => {
112+
const bundle = await rollup({
113+
input: 'catwoman.js',
114+
plugins: [html()]
115+
});
116+
const code = await getCode(bundle, { dir: 'output', format: 'esm' }, true);
117+
t.snapshot(code);
118+
});
119+
111120
test.serial('template', async (t) => {
112121
const bundle = await rollup({
113122
input: 'batman.js',

0 commit comments

Comments
Β (0)