From efafb7fcfb58bfdfcdc5cc09600e8479a98f9eb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juho=20Veps=C3=A4l=C3=A4inen?= Date: Sat, 4 Jan 2020 10:38:02 +0200 Subject: [PATCH 1/3] feat: Add support for `body` to default template Closes #19. --- README.md | 2 ++ __snapshots__/test.js.snap | 46 +++++++++++++++++++++++++------------- index.js | 5 +++-- test.js | 8 +++++++ 4 files changed, 43 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 7525085..cc75cac 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ const config = { title: 'Webpack demo', // Optional, defaults to `{ lang: 'en' }` htmlAttributes: { lang: 'en' }, + // Optional, any additional HTML attached within + body: '', // Optional cssAttributes: { rel: 'preload' }, // Optional diff --git a/__snapshots__/test.js.snap b/__snapshots__/test.js.snap index 354e955..d5f5da7 100644 --- a/__snapshots__/test.js.snap +++ b/__snapshots__/test.js.snap @@ -1,5 +1,19 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`additional body 1`] = ` +" + + + + + + + +
Demo
+ + " +`; + exports[`custom chunks 1`] = ` " @@ -8,8 +22,8 @@ exports[`custom chunks 1`] = ` - - + + " `; @@ -22,8 +36,8 @@ exports[`custom chunks 2`] = ` - - + + " `; @@ -36,8 +50,8 @@ exports[`custom filename 1`] = ` - - + + " `; @@ -50,8 +64,8 @@ exports[`custom js attribute 1`] = ` - - + + " `; @@ -64,8 +78,8 @@ exports[`custom lang 1`] = ` - - + + " `; @@ -78,8 +92,8 @@ exports[`custom publicPath 1`] = ` - - + + " `; @@ -94,8 +108,8 @@ exports[`custom title 1`] = ` Pizza - - + + " `; @@ -108,8 +122,8 @@ exports[`default options 1`] = ` - - + + " `; diff --git a/index.js b/index.js index 08be102..dd82dc6 100644 --- a/index.js +++ b/index.js @@ -81,6 +81,7 @@ function defaultTemplate({ htmlAttributes = { lang: 'en', }, + body = '', cssAttributes = {}, jsAttributes = {}, }) { @@ -105,8 +106,8 @@ function defaultTemplate({ ${title} ${cssTags} - - ${jsTags} + + ${body}${jsTags} `; } diff --git a/test.js b/test.js index 1ec228a..0cb7625 100644 --- a/test.js +++ b/test.js @@ -63,6 +63,14 @@ test('custom lang', () => { }); }); +test('additional body', () => { + return compiler({}, getConfig({ context: { body: '
Demo
' } })).then( + result => { + expect(result.compilation.assets['index.html']._value).toMatchSnapshot(); + } + ); +}); + test('custom js attribute', () => { return compiler( {}, From e99719528d28ec1d05fda44343864141069e0d83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juho=20Veps=C3=A4l=C3=A4inen?= Date: Sat, 4 Jan 2020 10:43:02 +0200 Subject: [PATCH 2/3] feat: Add support for head This is similar to body. --- README.md | 2 ++ __snapshots__/test.js.snap | 14 ++++++++++++++ index.js | 3 ++- test.js | 14 ++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index cc75cac..7112caa 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,8 @@ const config = { title: 'Webpack demo', // Optional, defaults to `{ lang: 'en' }` htmlAttributes: { lang: 'en' }, + // Optional, any additional HTML attached within + head: '', // Optional, any additional HTML attached within body: '', // Optional diff --git a/__snapshots__/test.js.snap b/__snapshots__/test.js.snap index d5f5da7..eebf39f 100644 --- a/__snapshots__/test.js.snap +++ b/__snapshots__/test.js.snap @@ -14,6 +14,20 @@ exports[`additional body 1`] = ` " `; +exports[`additional head 1`] = ` +" + + + + + + + + + + " +`; + exports[`custom chunks 1`] = ` " diff --git a/index.js b/index.js index dd82dc6..23dadf7 100644 --- a/index.js +++ b/index.js @@ -81,6 +81,7 @@ function defaultTemplate({ htmlAttributes = { lang: 'en', }, + head = '', body = '', cssAttributes = {}, jsAttributes = {}, @@ -104,7 +105,7 @@ function defaultTemplate({ ${title} - ${cssTags} + ${head}${cssTags} ${body}${jsTags} diff --git a/test.js b/test.js index 0cb7625..754562e 100644 --- a/test.js +++ b/test.js @@ -63,6 +63,20 @@ test('custom lang', () => { }); }); +test('additional head', () => { + return compiler( + {}, + getConfig({ + context: { + head: + '', + }, + }) + ).then(result => { + expect(result.compilation.assets['index.html']._value).toMatchSnapshot(); + }); +}); + test('additional body', () => { return compiler({}, getConfig({ context: { body: '
Demo
' } })).then( result => { From 1e789248013014aa24c60dadb4c2fe51b29d2e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juho=20Veps=C3=A4l=C3=A4inen?= Date: Sat, 4 Jan 2020 10:46:51 +0200 Subject: [PATCH 3/3] fix: Convert tabs to spaces --- __snapshots__/test.js.snap | 40 +++++++++++++++++++------------------- index.js | 4 ++-- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/__snapshots__/test.js.snap b/__snapshots__/test.js.snap index eebf39f..c73939c 100644 --- a/__snapshots__/test.js.snap +++ b/__snapshots__/test.js.snap @@ -8,8 +8,8 @@ exports[`additional body 1`] = ` - -
Demo
+ +
Demo
" `; @@ -22,8 +22,8 @@ exports[`additional head 1`] = ` - - + + " `; @@ -36,8 +36,8 @@ exports[`custom chunks 1`] = ` - - + + " `; @@ -50,8 +50,8 @@ exports[`custom chunks 2`] = ` - - + + " `; @@ -64,8 +64,8 @@ exports[`custom filename 1`] = ` - - + + " `; @@ -78,8 +78,8 @@ exports[`custom js attribute 1`] = ` - - + + " `; @@ -92,8 +92,8 @@ exports[`custom lang 1`] = ` - - + + " `; @@ -106,8 +106,8 @@ exports[`custom publicPath 1`] = ` - - + + " `; @@ -122,8 +122,8 @@ exports[`custom title 1`] = ` Pizza - - + + " `; @@ -136,8 +136,8 @@ exports[`default options 1`] = ` - - + + " `; diff --git a/index.js b/index.js index 23dadf7..53f1575 100644 --- a/index.js +++ b/index.js @@ -107,8 +107,8 @@ function defaultTemplate({ ${title} ${head}${cssTags} - - ${body}${jsTags} + + ${body}${jsTags} `; }