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
Adopt handlebars precompiled templates #1752
Conversation
Hmm! So it looks like after this PR, a few of the compiled files actually get larger.
(i checked gzip sizes and they get a tiny bit bigger as well: 520k to 525k and 92.5k to 96.4k) so it's not a win in filesize, at least. It might still be worth it for either runtime or complexity but i'm not sure about that yet. regardless, i really appreciate you giving this one a shot, @sendilkumarn! super interesting. |
@paulirish
|
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.
Nice work. Yeah the runtime require is key. :)
Happy this is in good shape.
WDYT, @ebidel? Shall we move ahead with this?
lighthouse-extension/gulpfile.js
Outdated
@@ -178,6 +207,14 @@ gulp.task('watch', ['lint', 'browserify', 'html'], () => { | |||
'app/src/**/*.js', | |||
'../lighthouse-core/**/*.js' | |||
], ['browserify']); | |||
|
|||
gulp.watch([ | |||
'../lighthouse-core/**/*.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.
this and the partials wildcard should overlap, right? does the order of these compile tasks matter?
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.
Yes. If we want to change anything, straightway in that precompiled file, this will help.
Order, yeah we have to run compile first and then browserify.
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.
So they can't be combined? Also can we utilize config.report
and config.partials
for the globs?
@@ -0,0 +1,283 @@ | |||
this["report"] = this["report"] || {}; |
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.
wondering if we should put this in gitignore instead.
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.
That is debatable. If we add in gitignore, we need to make sure that it will be generated on the fly for people who just clones the repo and runs node-cli command.
I like anything that makes our build smaller :) But I'm not sure we should have the compile steps as part of the extension/viewer. For one, it's duplicated code. It would be nice to have shared tasks in a |
Yeah that would be awesome. It will also solves the above comment |
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 is awesome stuff thanks @sendilkumarn!
Really unfortunate we're maintaining so many separate gulpfiles though :/ Also not a huge fan of introducing another forgettable build step when developing the CLI locally, especially a non-obvious one that requires you to run the watch of the extension to put files back into core. If we move forward with it, I agree with @ebidel on moving it up to a top-level gulpfile.
@@ -164,7 +150,11 @@ class ReportGenerator { | |||
Handlebars.registerHelper(helpers); | |||
} | |||
|
|||
Handlebars.registerPartial(audit.name, formatter.getFormatter('html')); | |||
const partials =reportPartials.report.partials; |
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.
nit: space after =
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.
wondering why eslint
did not complain ...
@@ -133,7 +119,7 @@ class ReportGenerator { | |||
* @return {string} HTML of the exception page. | |||
*/ | |||
renderException(err, results) { | |||
const template = Handlebars.compile(this.getExceptionTemplate()); | |||
const template = reportTemplate.report.template['exception']; |
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.
nit: .exception
const partials =reportPartials.report.partials; | ||
Handlebars.registerPartial(audit.name, | ||
Handlebars.template( | ||
partials[audit.name] ? partials[audit.name] : partials['empty-formatter'] |
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.
nit: partials[audit.name] || partials['empty-formatter']
Thanks @patrickhulce 👍 |
Added a gulp folder to write the common tasks and refer common tasks from there. |
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.
Nice drying up the gulpfiles :)
Up until now, we haven't checked in built files. Personally, I don't think we should start going down that road to be consistent with other places in the codebase.
gulp/compile-partials.js
Outdated
@@ -0,0 +1,19 @@ | |||
'use strict'; |
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.
Can you drop our license header in these new files?
@@ -43,6 +42,7 @@ const walkTree = new Promise((resolve, reject) => { | |||
}); | |||
|
|||
describe('Formatters', () => { | |||
/* TODO : Remove these tests and add appropriate tests based on handlebar pre-compiled templates | |||
it('has no formatters failing when getFormatter("html") is called', () => { |
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 use .skip
instead:
it.skip('processes an empty trace for screenshot data', () => { |
lighthouse-extension/gulpfile.js
Outdated
@@ -178,6 +207,14 @@ gulp.task('watch', ['lint', 'browserify', 'html'], () => { | |||
'app/src/**/*.js', | |||
'../lighthouse-core/**/*.js' | |||
], ['browserify']); | |||
|
|||
gulp.watch([ | |||
'../lighthouse-core/**/*.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.
So they can't be combined? Also can we utilize config.report
and config.partials
for the globs?
lighthouse-viewer/gulpfile.js
Outdated
], ['browserify']); | ||
}); | ||
gulp.watch([ | ||
'../lighthouse-core/**/*.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.
same comment here.
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.
Do you know why the null-formatter.html is being included in files changed?
Do we also need to update https://github.com/GoogleChrome/lighthouse/blob/master/.travis.yml to run gulp
? I would change https://github.com/GoogleChrome/lighthouse/blob/master/.travis.yml#L22-L24 to npm run build-all
and add your gulp
to the build-all
script: https://github.com/GoogleChrome/lighthouse/blob/master/package.json#L18
gulp/compile-report.js
Outdated
* Copyright 2017 Google Inc. All rights reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. |
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.
what do you think about combining these two files into one and exporting both functions? They're very similar.
changes to templates
@ebidel |
👍 for travis I think that will be enough. |
Well it is just an empty file. I created it. Before that null-formatter js will just return an empty string. Since we cannot use that for pre-compiling templates. Added that file |
Looks good @sendilkumarn! Did you see my comments on .travis.yml and package.json updates? #1752 (review) |
Yeah absolutely fine with that. I will add and push. |
033b20d
to
e50c840
Compare
package.json
Outdated
@@ -15,7 +15,7 @@ | |||
"install-cli": "cd ./lighthouse-cli && npm install", | |||
"install-extension": "cd ./lighthouse-extension && npm install", | |||
"install-viewer": "cd ./lighthouse-viewer && npm install", | |||
"build-all": "npm run build-cli && npm run build-extension && npm run build-viewer", | |||
"build-all": "npm run build-cli && npm run build-extension && npm run build-viewer && gulp", |
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.
Shouldn't gulp
be first so the templates are compiled by the time other places need them?
changed the order of build running gulp at first
e50c840
to
0b4e544
Compare
@ebidel yeah exactly. Thanks 👍 |
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.
LGTM from me. I'll keep open if anyone else has further comments.
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.
thanks for all this work!
package.json
Outdated
@@ -24,7 +24,7 @@ | |||
"coverage": "node $(npm bin)/istanbul cover -x \"**/third_party/**\" _mocha -- $(find */test -name '*-test.js') --timeout 10000 --reporter progress", | |||
"coveralls": "npm run coverage && cat ./coverage/lcov.info | coveralls", | |||
"start": "node ./lighthouse-cli/index.js", |
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.
do we want to add gulp to start too since it won't be able to run without it now?
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 leaning towards not incurring that cost every start, but a note in the README or something would be nice :)
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.
do we need to have pre-compiled templates for global installs
? currently we are ignoring those.
I added gulp as an extra step in develop
section. [Edited]
Huge. Thanks @sendilkumarn for taking this on. This was a yeoman's work and we're really jazzed about it. |
Thank you 👍 |
#1448
@paulirish this will need us to run
watch
even when we are testing locally oncli
, in order to compile the templated. Otherwise we have to split the generateReport into 2 different methods one handles with html files and other with precompiled template file.Note: This is my first attempt with precompile ;)