Replace ejs templates with a simple js file#397
Replace ejs templates with a simple js file#397valscion merged 6 commits intowebpack:masterfrom realityking:templates
Conversation
|
Please fix lint errors |
| </html>`; | ||
| } | ||
|
|
||
| exports.renderViewer = renderViewer; |
There was a problem hiding this comment.
Let's move it above escapeJson function declaration please so exported members become clearly visible.
| } | ||
|
|
||
| function renderViewer({title, enableWebSocket, chartData, defaultSizes, mode} = {}) { | ||
| return `<!DOCTYPE html> |
There was a problem hiding this comment.
I see a few drawbacks of this approach:
- No syntax highlighting
- Much more difficult to do conditional branching e.g.
if/elseif we'll need it in the future. - You have to remember to call
_.escapemanually
There was a problem hiding this comment.
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.
- 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 |
|
@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 |
| ejs.renderFile( | ||
| `${projectRoot}/views/viewer.ejs`, | ||
| { | ||
| try { |
There was a problem hiding this comment.
Looks like there is no need in promise here anymore. The code is sync
There was a problem hiding this comment.
It will be a breaking change.
There was a problem hiding this comment.
I mean the function can be still async but promise wrapper around sync code is not necessary.
There was a problem hiding this comment.
Ah, yep, agree. @realityking could you change it please?
There was a problem hiding this comment.
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? |
| if (openBrowser) { | ||
| open(`file://${reportFilepath}`, logger); | ||
| } | ||
| }); |
There was a problem hiding this comment.
this line should not be here I think
There was a problem hiding this comment.
You're right. I wonder how the tests worked with this line present 🤔
There was a problem hiding this comment.
They didn't. Travis hangs.
valscion
left a comment
There was a problem hiding this comment.
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-analyzeruses 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.