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

Generate ES5 #42

Merged
merged 3 commits into from
Aug 29, 2018
Merged

Generate ES5 #42

merged 3 commits into from
Aug 29, 2018

Conversation

romgrk
Copy link
Contributor

@romgrk romgrk commented Aug 27, 2018

Closes #3, #10

This PR adds a webpack config to generate ES5 for distribution. It fixes multiples issues that arise when trying to compile this package in production mode, notably with create-react-app.

I was not sure what the other webpack configs did, so if you'd like one of them to be replaced by the one that is added here, let met know (or edit this branch yourself).
The additionnal config outputs a file at ./dist/es5.js, which can be used by user by importing from 'pts/dist/es5.js'. If you'd prefer that this file be used as the package main, again let me know or edit yourself.

Note: Class Pt extends Float32Array directly instead of PtBaseArray because babel-plugin-transform-builtin-extend doesn't see that it's extending a builtin otherwise.

@williamngan
Copy link
Owner

Hi @romgrk , many thanks for this!

Have you try testing this with create-react-app? I gave it a quick try using npm link and it's giving me an error on:

Failed to minify the code from this file:

        ./node_modules/pts/dist/es2015/Pt.js:5

I think probably the es2015 module is interfering with it. Wonder if you have encountered this also?

@romgrk
Copy link
Contributor Author

romgrk commented Aug 28, 2018

Hey @williamngan, yes, as a matter of fact I've spent time on this because it prevented me from packaging a create-react-app.

I might have been unclear, but the current behavior is:

  • a new transpiled file is added at ./dist/es5.js
  • the old files at ./dist/es2015/ are untouched
  • the module field of package.json still points at ./dist/es2015/_module.js

To use with create-react-app, one must import 'pts/dist/es5.js', not 'pts'.

I've left it as such for the moment because I needed to discuss some points with you:

  • There are already 3 others webpack config files: should we remove any of those?
  • Should we replace the module field with the new ES5 transpiled code? I wondered you might have reasons to distribute ES6 code, although I don't see any.

Let me know your answers for those 2 questions and I'll update the PR.

Thanks!

@williamngan
Copy link
Owner

Got it. This is super cool -- having a es5 build would help Pts work with a wide range of projects. So thank you so much! 🙏

I think I'll prefer to keep es5.js for now, and think about updating webpack.mod later on. Because es6 build seems to result in smaller file size -- and if I understand correctly, it will also be easier to do tree-shaking. Also newer tools like neutrino.js can already build es6 + react with zero config, and I believe the next version create-react-app will too. It's a bit hard to keep track of javascript development these days :)

I'll merge this now and do some small touch-ups. Thank you again!

@williamngan williamngan merged commit a45bf92 into williamngan:master Aug 29, 2018
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.

Create React App build fails to minify
2 participants