Skip to content
Merged
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const config = {
title: 'Webpack demo',
// Optional, defaults to `{ lang: 'en' }`
htmlAttributes: { lang: 'en' },
// Optional, any additional HTML attached within <head>
head: '',
// Optional, any additional HTML attached within <body>
body: '',
// Optional
cssAttributes: { rel: 'preload' },
// Optional
Expand Down
28 changes: 28 additions & 0 deletions __snapshots__/test.js.snap
Original file line number Diff line number Diff line change
@@ -1,5 +1,33 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`additional body 1`] = `
"<!DOCTYPE html>
<html lang=\\"en\\">
<head>
<meta charset=\\"UTF-8\\">
<title></title>

</head>
<body>
<div>Demo</div><script src=\\"runtime~main.js\\"></script><script src=\\"main.js\\"></script>
</body>
</html>"
`;

exports[`additional head 1`] = `
"<!DOCTYPE html>
<html lang=\\"en\\">
<head>
<meta charset=\\"UTF-8\\">
<title></title>
<meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1.0\\" />
</head>
<body>
<script src=\\"runtime~main.js\\"></script><script src=\\"main.js\\"></script>
</body>
</html>"
`;

exports[`custom chunks 1`] = `
"<!DOCTYPE html>
<html lang=\\"en\\">
Expand Down
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ function defaultTemplate({
htmlAttributes = {
lang: 'en',
},
head = '',
body = '',
cssAttributes = {},
jsAttributes = {},
}) {
Expand All @@ -103,10 +105,10 @@ function defaultTemplate({
<head>
<meta charset="UTF-8">
<title>${title}</title>
${cssTags}
${head}${cssTags}
</head>
<body>
${jsTags}
${body}${jsTags}
</body>
</html>`;
}
Expand Down
22 changes: 22 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,28 @@ test('custom lang', () => {
});
});

test('additional head', () => {
return compiler(
{},
getConfig({
context: {
head:
'<meta name="viewport" content="width=device-width, initial-scale=1.0" />',
},
})
).then(result => {
expect(result.compilation.assets['index.html']._value).toMatchSnapshot();
});
});

test('additional body', () => {
return compiler({}, getConfig({ context: { body: '<div>Demo</div>' } })).then(
result => {
expect(result.compilation.assets['index.html']._value).toMatchSnapshot();
}
);
});

test('custom js attribute', () => {
return compiler(
{},
Expand Down