Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(html): Template files should only include entry chunks #688

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 1 addition & 3 deletions packages/html/src/index.ts
Expand Up @@ -6,9 +6,7 @@ import { RollupHtmlOptions, RollupHtmlTemplateOptions } from '../types';

const getFiles = (bundle: OutputBundle): RollupHtmlTemplateOptions['files'] => {
const files = Object.values(bundle).filter(
(file) =>
file.type === 'chunk' ||
(typeof file.type === 'string' ? file.type === 'asset' : file.isAsset)
(file: any) => file.isEntry || !file.fileName.endsWith('.js')
shellscape marked this conversation as resolved.
Show resolved Hide resolved
);
const result = {} as ReturnType<typeof getFiles>;
for (const file of files) {
Expand Down
84 changes: 84 additions & 0 deletions packages/html/test/snapshots/test.js.md
Expand Up @@ -353,3 +353,87 @@ Generated by [AVA](https://ava.li).
toString: Function {},
},
]

## template files should only include entry chunks

> Snapshot 1

[
{
code: `import './batman-dce5b48d.js';␊
// eslint-disable-next-line␊
`,
fileName: 'robin.js',
map: null,
source: undefined,
},
{
code: `␊
`,
fileName: 'batman-dce5b48d.js',
map: null,
source: undefined,
},
{
code: undefined,
fileName: 'index.html',
map: undefined,
source: `␊
<!doctype html>␊
<html lang="en">␊
<head>␊
<meta charset="utf-8">␊
<title>Rollup Bundle</title>␊
</head>␊
<body>␊
<script src="robin.js" type="module"></script>␊
</body>␊
</html>`,
},
]

## template files should not include js assets

> Snapshot 1

[
{
code: `(function (factory) {␊
typeof define === 'function' && define.amd ? define(factory) :␊
factory();␊
}((function () { 'use strict';␊
})));␊
`,
fileName: 'robin.js',
map: null,
source: undefined,
},
{
code: undefined,
fileName: 'assets/asset-37a63f1f.js',
map: undefined,
source: '',
},
{
code: undefined,
fileName: 'index.html',
map: undefined,
source: `␊
<!doctype html>␊
<html lang="en">␊
<head>␊
<meta charset="utf-8">␊
<title>Rollup Bundle</title>␊
</head>␊
<body>␊
<script src="robin.js" type="module"></script>␊
</body>␊
</html>`,
},
]
Binary file modified packages/html/test/snapshots/test.js.snap
Binary file not shown.
30 changes: 30 additions & 0 deletions packages/html/test/test.js
Expand Up @@ -120,3 +120,33 @@ test.serial('template', async (t) => {
const code = await getCode(bundle, output, true);
t.snapshot(code);
});

test.serial('template files should only include entry chunks', async (t) => {
const bundle = await rollup({
input: 'robin.js',
manualChunks: {
batman: ['batman.js']
},
plugins: [html()],
treeshake: false
});
const outputOptions = { ...output, format: 'es' };
const code = await getCode(bundle, outputOptions, true);
t.snapshot(code);
});

test.serial('template files should not include js assets', async (t) => {
const bundle = await rollup({
input: 'robin.js',
plugins: [
{
generateBundle() {
this.emitFile({ name: 'asset.js', source: '', type: 'asset' });
}
},
html()
]
});
const code = await getCode(bundle, output, true);
t.snapshot(code);
});