Skip to content

Commit 47829cf

Browse files
committed
create pretty html plugin
1 parent dbc8b95 commit 47829cf

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

gatsby-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ module.exports = {
2121
'gatsby-plugin-netlify',
2222
'gatsby-plugin-resolve-src',
2323
'gatsby-transformer-remark',
24+
'pretty-html',
2425
{
2526
resolve: 'gatsby-plugin-typescript',
2627
options: {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
"gatsby-plugin-typescript": "^2.0.6",
4141
"gatsby-source-filesystem": "^2.0.20",
4242
"gatsby-transformer-remark": "^2.2.4",
43+
"js-beautify": "^1.8.9",
4344
"react": "^16.7.0",
4445
"react-dom": "^16.7.0",
4546
"react-helmet": "^5.2.0",

plugins/pretty-html/gatsby-ssr.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const { renderToString } = require('react-dom/server')
2+
const jsbeautify = require('js-beautify')
3+
4+
exports.replaceRenderer = ({ bodyComponent, replaceBodyHTMLString }) => {
5+
const bodyHTML = renderToString(bodyComponent)
6+
const prettyHTML = jsbeautify.html(bodyHTML, { indent_size: 2 })
7+
replaceBodyHTMLString(prettyHTML)
8+
}

plugins/pretty-html/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "pretty-html",
3+
"author": "Aaron Lampros <[email protected]>"
4+
}

0 commit comments

Comments
 (0)