-
-
Notifications
You must be signed in to change notification settings - Fork 488
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
Replace ejs templates with a simple js file #397
Conversation
5142bad
to
d621a7a
Compare
Please fix lint errors |
d621a7a
to
ac2f75b
Compare
src/template.js
Outdated
</html>`; | ||
} | ||
|
||
exports.renderViewer = renderViewer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move it above escapeJson
function declaration please so exported members become clearly visible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/template.js
Outdated
} | ||
|
||
function renderViewer({title, enableWebSocket, chartData, defaultSizes, mode} = {}) { | ||
return `<!DOCTYPE html> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a few drawbacks of this approach:
- No syntax highlighting
- Much more difficult to do conditional branching e.g.
if/else
if we'll need it in the future. - You have to remember to call
_.escape
manually
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not saying that I'm strongly against this PR, no. We can live with these drawbacks, but only if it brings some significant improvements. That's why I asked to provide difference in node_modules
sizes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Syntax highlighting could be added in some editors/plugins by adding a "fake" tag
html
. I'll add that as a commit so you can see what it looks like. - Agreed that conditionals are more cumbersome but do you expect the templates to get significantly more complex than they are today?
- This is true (though you also have to be mindful of
<%=
vs<%-
in EJS) and I wouldn't do it for a large server rendered app but as of today there's just two variables in the templates here that need to be escaped.
To me, this is trade-off of complexity. EJS is certainly nicer than template literals but for a template this small it's, IMHO, not worth the cost of the dependencies. Some of which are very old and don't even deduplicate.
Could you also provide a difference between |
ac2f75b
to
d44be8f
Compare
@realityking may I ask you to not use force-push in the future please as it significantly complicates tracking of changes. |
ejs started to depend on jake build tool since v3 for some reason. v2 was dependency free. |
Sorry about the force push, I'll refrain from them. The size difference in |
Just to further illustrate this point, these are the dependencies that would no longer be required:
|
Hmm, I wonder why do they need build tool as runtime dependency? |
They use it to build cli mde/ejs@82a0309#diff-ca900686fca4680d4692bf587dc5da1322879c344688c187b5511cda27902c18R20 |
src/viewer.js
Outdated
ejs.renderFile( | ||
`${projectRoot}/views/viewer.ejs`, | ||
{ | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like there is no need in promise here anymore. The code is sync
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will be a breaking change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean the function can be still async but promise wrapper around sync code is not necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yep, agree. @realityking could you change it please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pushed a commit to do this :)
This approach is looking really promising to me! I'd be happy if we could make this pipeline easier by removing the ejs templates. I'm thrilled to see your contributions, @TrySound and @realityking ❤️. I hope you're not feeling discouraged as we are a bit slow to look through your changes — rest assured that we are happy to see you contribute to webpack-bundle-analyzer 😊 EDIT: Oops, forgot to ping you both 😅 |
@valscion I was confused when I got the email 😄 So far, I'm really not concerned about review times. I realize nobody is working full-time on this. 🙂 |
Ok, let's merge this. I think removing an extra dependency outweighs the drawbacks. @valscion WDYT? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thoughts: 🎉 😄
src/viewer.js
Outdated
|
||
if (openBrowser) { | ||
open(`file://${reportFilepath}`, logger); | ||
} | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line should not be here I think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I wonder how the tests worked with this line present 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They didn't. Travis hangs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this looks good to me! If you feel like adding a changelog entry, that would be amazing
Done :) |
I'll close and reopen the PR to see if Travis build would start up... I want to merge this PR 😄 |
@valscion It looks like Switching to .com, or somewhere else entirely, would be a good idea. |
Maybe github actions is better idea, most of webpack repos already migrate on it |
Yeah I have been wondering if github actions would be a good idea. A PR for that would be appreciated |
I merged this PR now as I got tired of waiting on Travis. |
Thanks @valscion :) Let's hope I didn't overlook anything. Please ping in case master does error out and I'll fix it ASAP. |
Released in v4.2.0 |
This PR replaces the EJS based templates with a simple JS file using template strings.
webpack-bundle-analyzer
uses very little HTML templating since most of the client is a SPA. What is used, can be replaced by a straightforward JS file. This drops 15(!) packages from the dependencies. I also like how all functions related to generating the HTML get pulled into the same file.