-
Notifications
You must be signed in to change notification settings - Fork 943
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 #790
Comments
Could you get the same benefit by using an ES6 import statement declaring specific functions your modules will use? E.g. import { difference } from '@turf/turf' |
Full disclosure: I'm saying this by reading the source of the turf package, I haven't actually tested it. So, currently the docs recommend to install each package corresponding to the function you use. For example,
The problem with that second option is that the bundler will include in the bundler every function, because the turf module includes every function, even if you don't import it in any module. That's like this because the turf package index.js requires every function. However, if that file instead of exporting like this:
exports like this:
the exported modules would be ES6 modules. That means that bundlers that support tree shaking (webpack and rollup) could remove unused code, even if you install the main turf package. |
Good explanation, thank you. I was hoping webpack tree-shaking would figure out the minimal dependencies with the current 'require' declarations. But I guess it doesn't from what you say. I'm no expert on webpack, myself. |
We could use ES6 modules ONLY in As for all the TurfJS modules, they should remain in ES5 since NodeJS still does not natively support I'm 👍 if
CC: @morganherlocker |
Exactly. That's at least what it says in the Rollup docs. I thought webpack also supported it, but there's an issue with a back and forth about this. Give me a day and I'll test that pull request you created against rollup and webpack to see if it works. |
👍 Sounds like a plan. |
I'm sorry, I've been really busy, and didn't have the time to do it. Hopefully this week I'll test it. |
No worries, adding 'module' sounds like the best solution. |
Implemented with PR #793. |
Hello. Awesome project. Is there a possibility of exporting ES6 modules? This would allow to install just the main turf dependency and then let tree shaking remove everything unused.
The text was updated successfully, but these errors were encountered: