Skip to content
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

Use babel in the build process. #900

Merged
merged 4 commits into from
Aug 23, 2018
Merged

Use babel in the build process. #900

merged 4 commits into from
Aug 23, 2018

Conversation

manthey
Copy link
Contributor

@manthey manthey commented Aug 17, 2018

This uses babel as a webpack loader to preprocess source files. It uses babel-preset-env to decide what browsers to target, using browsers: ['defaults'] as the criterion. Perhaps we want to explicitly target a set of browsers.

This resolves #418.

@manthey manthey force-pushed the use-babel branch 2 times, most recently from 72413c0 to c4a967d Compare August 20, 2018 12:22
@manthey
Copy link
Contributor Author

manthey commented Aug 21, 2018

This is probably a good point to introduce a general set of polyfills to continue to support the oldest browsers we want to handle. Specifically, babel-preset-env by itself will ensure language features, but not standard library features (such as Promise support in IE 11). To handle that, we can use babel-polyfill and karma-phantomjs-shim. The babel-preset-env options can then be used to remove undesired browsers so the built geo.js package doesn't become needless large.

Copy link
Member

@aashish24 aashish24 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am less familiar with babel but the changes looks reasonable. Perhaps @zachmullen can approve this branch?

zachmullen
zachmullen previously approved these changes Aug 21, 2018
Copy link
Contributor

@zachmullen zachmullen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

aashish24
aashish24 previously approved these changes Aug 21, 2018
@manthey
Copy link
Contributor Author

manthey commented Aug 21, 2018

There is something amiss with how coverage is being generated. I'm looking in to it.

@zachmullen
Copy link
Contributor

We use babel-plugin-istanbul to get coverage working with babel.

@manthey
Copy link
Contributor Author

manthey commented Aug 21, 2018

Using babel-plugin-istanbul or switching from karma-coverage to karma-coverage-istanbul-reporter both sort of work but have issues. Specifically, the emitted coverage seems to reference columns that only exist in the transpile code.

@manthey
Copy link
Contributor Author

manthey commented Aug 22, 2018

It turns out my issue with coverage was caused by using Babel 7 and, switching back to Babel 6, on where babel-polyfills was required. I've switched to Babel 6 and only added the polyfills to the non-lean build (and also require them in testing).

Babel 7 supports only adding polyfills for features that are used,
resulting in a smaller bundle than babel 6.

By using karma-phantomjs-shim and @babel/polyfills, we no longer need
our own polyfills module.
Babel 7 is still pending official release and causes some issues.  Babel
7.0.0-rc.2 throws errors where 7.0.0-rc.1 does not.  Rather than figure
out what causes these, I recommend we wait until it is officially
released.  The main benefit of Babel 7 is that the polyfills can be
added conditionally based on actual use.

When adding babel-polyfill to src/index.js, the coverage for index.js is
wrong (the line numbers are incorrect).  Further, babel-polyfill is
fairly heavy, so just add it to the vendor.js (geo.js not geo.lean.js).
It also needs to be added to the test-utils to ensure that we can use
new language features in the tests with PhantomJS.  Reference to
babel-polyfill has been moved to src/polyfills.js, and that file has
been excluded from coverage analysis.

For the coverage reporters, disable the html reporter as it fails with
karma-coverage and babel.  One solution would be to switch to
karma-coverage-istanbul-reporter, but I don't think the html coverage is
strictly necessary as we use codecov.
@manthey manthey dismissed stale reviews from aashish24 and zachmullen August 23, 2018 13:31

Fixed coverage and polyfill issues.

@manthey
Copy link
Contributor Author

manthey commented Aug 23, 2018

@zachmullen Can you review this again, please.

@@ -34,16 +34,17 @@ module.exports = function (config) {
karma_config.specReporter = {suppressPassed: true, suppressSkipped: true};
karma_config.coverageReporter = {
reporters: [
{type: 'html', dir: 'dist/coverage/', subdir: subdir_name},
// {type: 'html', dir: 'dist/coverage/', subdir: subdir_name},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless there's a good reason, we should probably remove unused lines rather than commenting them out.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do. Thanks.

@manthey manthey merged commit 1ec38a4 into master Aug 23, 2018
@manthey manthey deleted the use-babel branch August 23, 2018 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider using ES6 (EMCA6) feature using Babel
3 participants