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 es6 modules and webpack in prep for NPM publish #265

Merged
merged 17 commits into from Jan 3, 2018

Conversation

jaimedp
Copy link
Contributor

@jaimedp jaimedp commented Dec 9, 2017

A lot of changes. I tried to do the messy change of removing and re-indenting files on the first commit and then fixes on the following commits to make it a bit easier to see, but it is still hard to see the changes :(

@narenranjit
Copy link
Contributor

narenranjit commented Dec 13, 2017

Great! Adding ?w=1 to github diff url ignores whitespace so wasn't too bad to see changes :) Few thoughts:

  • Maybe I missed it but are we not exposing nwt publicly? Some examples like (http://forio.com/contour/gallery.html#/chart/scatter/scatter-trendline) depend on a few functions from that so we should.
  • We should probably export it as Contour.utils instead?
  • Can we replace the lodash functions in contour-utils with the actual lodash imports? We can import those specific functions without bundling all of lodash.

@narenranjit
Copy link
Contributor

Also, in the spirit on modernizing jshintrc -> eslintrc ?



export const axes = {};
export const addAxis = (name, axisCtor) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason not to export function addAxis instead? afaik exporting a const arrow function will show up as anonymous in stacktraces, while exporting named functions will list it 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.

I don't think it makes any difference for the stacktrace, I test all the options and the traces still get the correct function name... then found this
http://lukecod.es/2015/12/01/es6-arrow-function-stack-traces/

@narenranjit
Copy link
Contributor

What're the before/after file-sizes of contour.min.js?

Jaime del Palacio added 2 commits December 14, 2017 20:40
…fic options.

This was an issue on the order of merging of options with the visualization options
@jaimedp
Copy link
Contributor Author

jaimedp commented Dec 15, 2017

  • I added Contour.utils to expose nwt to the rest of the world.
  • I think we can keep the custom lodash replacements for now.. I think breaking up with lodash should be complete :)
  • I have another branch with eslint and all the fixes for linting but I think we should finish and merge this branch first
  • The size of the new min.js file is ~82k, the previous one was ~78k, so is ~4K larger for the stuff that webpack injects I guess

Also, for publishing to npm, you'll need to create an npm user for forio and make sure the author info in package.json matches with the user, so we can publish it.

@narenranjit
Copy link
Contributor

Looks good!

  • Lodash is overkill for the isObject etc of course, but why not use it for the merge, defaults etc? The less code under our maintenance purview and the more we handoff to established libraries the better, unless there's a reason not to?

  • We should whitelist IE11 in preset-env.

@jaimedp
Copy link
Contributor Author

jaimedp commented Dec 15, 2017

  • Lodash... Yeah, it makes sense.
  • IE11... I was thinking the same thing last night, I guess I forgot to do it :)

I'll update the PR tonight.

One more thing to note. I removed the /dist folder from the repo, this means that you will no longer be able to use bower install since it does not have a post-install build. Just to make sure you're ok completely dropping support for bower.

Also, we need to remember to update contour.geo too with this changes.

@narenranjit
Copy link
Contributor

narenranjit commented Dec 15, 2017

I'd forgotten bower existed till I tried to build contour last week, so fine dropping it :)

Tangentially, we've given up on making millions with Contour-advanced so contents of that repo should go somewhere public, just not sure where. Thoughts? Just new showcase examples? (I'll get you access to the advanced repo in a bit).

@jaimedp
Copy link
Contributor Author

jaimedp commented Dec 19, 2017

Moved to use lodash.merge and lodash.defaults (increase in size of the minified file by ~13k). Also added ie11 to the env in babel and fixed 267 & 268.

Regarding advance viz, I think it would be good if they had their place in te showcase and then you could just install them like npm install contour.drawable or something like that

@narenranjit
Copy link
Contributor

narenranjit commented Dec 20, 2017

I'm having second thoughts about not including dist, though more about workflow than anything technical.

For new PRs it's useful to have devs include a jsfiddle in their example pointing to a jsfiddle demoing their change, for e.g. see #251 which has http://jsfiddle.net/3yqyvdud/4/ which points to a pre-built contour file for that PR, pulled from the incoming dist. This really reduces the friction of testing PRs, and puts the onus of making sure it builds/works on the submitter.

Thoughts/ suggestions for a better workflow?

@jaimedp
Copy link
Contributor Author

jaimedp commented Dec 31, 2017

Hey, I see the point of evaluating PRs from a jsfiddle, but I think you'd end up with unnecessary merge conflicts which is minor, but the bigger problem I think it is that you end up with a very confusing versioning, since the /dist folder no longer contains the "official" released version, it has whatever the latest merge puts there, if it didn't forget to build it... for example in cases where the PR does not need to be js tested (ie. changes to less files or docs), then the /dist folder is not even the latest/edge version, is just a random snapshot.

There is one posible solution, but it would mean to drop the bundle of the lodash merge/default functions. The solution is to include the /src/scripts/index.js file as a <script type="module"> that way (with some tweaks) it works, but it limits to import only files addressable from the src folder (ie. no node_modules).

I did a proof of concept jsfiddle here

The changes required for this to work an on this commit

I still don't think it would be a good solution, since it imposes an unnatural limit to what you can use, but I wanted to test what it would look like :)

@narenranjit
Copy link
Contributor

narenranjit commented Jan 2, 2018

You can prevent merge conflicts / large diffs on dist if you mark minified files as "binary" in gitattributes (see https://github.com/forio/flow.js/blob/master/.gitattributes for e.g. https://blog.andrewray.me/dealing-with-compiled-files-in-git/ for more info).

I don't think dist contour.js being of uncertain freshness is that big a deal, if you're explicitly copying source from github instead of cdn/npm you hopefully know what you're doing :)

Source type module is an interesting idea, let me play around with that.

@narenranjit narenranjit merged commit 5372ab4 into forio:master Jan 3, 2018
@jaimedp jaimedp deleted the npm branch January 24, 2018 05:08
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.

None yet

2 participants