Skip to content

Commit

Permalink
fix: Only prettify HTML in production (#74)
Browse files Browse the repository at this point in the history
The prettification is kinda heavy on computing time. To reduce the load during development, this will only be executed in production.
  • Loading branch information
mvsde committed Dec 15, 2019
1 parent 1a6c241 commit 4e074f9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
7 changes: 6 additions & 1 deletion lib/webpack/pangolin-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,15 @@ module.exports = function (source) {
return callback(error)
}

// Skip prettifying in development.
const prettifiedRender = process.env.NODE_ENV === 'production'
? prettifyRender(render)
: render

const highlightedSource = highlightSource(source)

this.emitFile(`${outputName}/index.html`, generateIndex())
this.emitFile(`${outputName}/render.html`, prettifyRender(render))
this.emitFile(`${outputName}/render.html`, prettifiedRender)
this.emitFile(`${outputName}/source.html`, highlightedSource)

callback(null, '')
Expand Down
5 changes: 4 additions & 1 deletion test/unit/lib/utils/fixtures/ugly.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
<img
alt="Lorem ipsum dolor sit amet"
src=""
class="js-different-thing-img"
class="hello
world
js-different-thing-img"


width="800" height="451"
Expand Down
5 changes: 4 additions & 1 deletion test/unit/lib/utils/snapshots/prettify-render.spec.js.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ Generated by [AVA](https://ava.li).
<img␊
alt="Lorem ipsum dolor sit amet"␊
src=""␊
class="js-different-thing-img"␊
class="hello␊
world␊
js-different-thing-img"␊
width="800"␊
height="451"␊
/>␊
Expand Down
Binary file modified test/unit/lib/utils/snapshots/prettify-render.spec.js.snap
Binary file not shown.

0 comments on commit 4e074f9

Please sign in to comment.