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

Feature/bump deps #255

Merged
merged 2 commits into from
Nov 24, 2017
Merged

Feature/bump deps #255

merged 2 commits into from
Nov 24, 2017

Conversation

themre
Copy link
Contributor

@themre themre commented Nov 23, 2017

I bumped dependencies and fixed webpack config so it works with latest stuff. also, probably due to new versoin of turf, we reduced size from 1.3 MB to 540 kB 🎉 tried a little bit and everything seems to work.

@codeofsumit codeofsumit merged commit 40b3abb into geoman-io:develop Nov 24, 2017
@codeofsumit
Copy link
Contributor

codeofsumit commented Nov 24, 2017

ha! Awesome! I tried to do the same yesterday and failed at the webpack config
Still, the bundle size is not lower.
This is the latest leaflet.pm.min.js on the CDN:
https://unpkg.com/leaflet.pm@0.22.0/dist/leaflet.pm.min.js

It's 510KB.

Turf accounts for around 450KB in that . And afaik, turf did not replace the reason for that (JSTS) with a smaller library yet => sadly no bundle size improvement.

Will still merge this though thanks for this!!!

FYI: When turf finally moves from JSTS to martinez, leaflet.pm should be around 60 - 80KB.

@themre
Copy link
Contributor Author

themre commented Nov 24, 2017

hm, strange because before bumping turf to 5.x I had 1.3 MB :D perhaps the problem is, that these modules are all connected and it adds that bundle size. I could try with different lib.

@codeofsumit
Copy link
Contributor

The 1.3MB is unminified afaik.
If you're able to replace turf with other smaller libraries that do the two big functions that I use from turf (difference and intersect) it'd make a huge difference. Will be hard to find good ones though

@themre
Copy link
Contributor Author

themre commented Nov 24, 2017

should we try rollup?

@codeofsumit
Copy link
Contributor

We can but I don't think it makes a difference and here's why:

leaflet.pm is 500KB

  • leaflet core: 50KB
  • turf: 450KB

If Rollup also reduced the size of dependencies - we can try it.
But if turf is already bundled with Rollup, what difference does it make for us? We'd still get 450KB from turf that was already bundled by Rollup. If our Rollup implementation would make that smaller it would be very weird.

What do you think?

@codeofsumit
Copy link
Contributor

codeofsumit commented Nov 24, 2017

@DenisCarriere can you chim in here? Can you give us more info if Rollup in our build would reduce the Turf build size? Or is Turf already bundled and optimized by Rollup?

@themre
Copy link
Contributor Author

themre commented Nov 24, 2017

another thing I noticed is leaflet already has intersects method and they have ES modules.

@DenisCarriere
Copy link
Contributor

At the moment the JSTS library isn't working perfectly to perform the Tree shaking properly. I'm currently working on refactoring JSTS for the sole purpose of adding it in TurfJS to minimize the code base and to allow the Tree Shaking to happen.

We should be able to push that release out at the next minor release.

@turf/intersect uses JSTS, so this will have the same Tree Shaking issue I mentioned.

Right now Rollup isn't doing a great job at handling JSTS because of extend.js & inherits.js which makes a copy of the Class thus making the repo even larger.

@themre themre deleted the feature/bump-deps branch November 24, 2017 11:27
@DenisCarriere
Copy link
Contributor

@codeofsumit How many TurfJS modules are you using in leaflet.pm? I can try to make sure those modules for the next minor release are refactored to properly support Rollup.

@themre
Copy link
Contributor Author

themre commented Nov 24, 2017

"turf/difference": "^5.0.4",
"turf/intersect": "^5.0.4",
"turf/kinks": "^5.0.4"
thanks for help!

@DenisCarriere
Copy link
Contributor

DenisCarriere commented Nov 24, 2017

which ones?

Code block the JSON object

@themre
Copy link
Contributor Author

themre commented Nov 24, 2017

i updated the comment, sorry. difference, intersect and kinks. I see there is also a bug with kinks: Turfjs/turf#1094

@DenisCarriere
Copy link
Contributor

The 🐛 bug in kinks is only for 1 test case, it's still fine to use for most scenarios.

@themre
Copy link
Contributor Author

themre commented Nov 24, 2017

@DenisCarriere btw, i saw that you mentioned somewhere that this is one way to import jsts features without turf, but need to use rollup: https://github.com/bjornharrtell/topolis/blob/master/src/utils.js. or am I mistaken?

@themre
Copy link
Contributor Author

themre commented Nov 24, 2017

I started a PR with rollup (#256), some size descrease is noticed, however only with unminified version, because there is the same bug as here: Turfjs/turf#1086

@DenisCarriere
Copy link
Contributor

@themre I've just published a new refactored version of JSTS which drops the extend.js (the cause of the error).

Try using this with Rollup and your configuration to see if you are still experiencing the same issues.

$ npm install turf-jsts

You can use @turf/intersect's source code as an example of how to use jsts, just need to replace jsts-es with turf-jsts (will most likely be renamed to jsts-es if it's stable)

import { GeoJSONReader, GeoJSONWriter, OverlayOp } from 'turf-jsts';

function intersect(poly1, poly2) {
    var geom1 = getGeom(poly1);
    var geom2 = getGeom(poly2);

    var reader = new GeoJSONReader();
    var a = reader.read(geom1);
    var b = reader.read(geom2);
    var intersection = OverlayOp.intersection(a, b);

    // https://github.com/Turfjs/turf/issues/951
    if (intersection.isEmpty()) return null;

    var writer = new GeoJSONWriter();
    var geom = writer.write(intersection);
    return feature(geom);
}

@themre
Copy link
Contributor Author

themre commented Nov 25, 2017

thank you very much!

@themre
Copy link
Contributor Author

themre commented Nov 25, 2017

I've tried with turf-jsts, but now I get this error:
[!] (uglify plugin) Error: Error transforming bundle with 'uglify' plugin: Unexpected token: name (NumberUtil)
I'll try to find some debug log to give some info.

@DenisCarriere
Copy link
Contributor

Well turf-jsts is pure ES6, so you'll need to use Babel before you apply uglify, but I can look into it as well to see where it's coming from.

@themre
Copy link
Contributor Author

themre commented Nov 25, 2017

I already have babel:

babel({
      presets: [['env', {
        modules: false,
        targets: {
          browsers: ['> 2%']
        }
      }]],
      exclude: [
        'node_modules/**',
        '*.json'
      ],
      babelrc: false
    })

@DenisCarriere
Copy link
Contributor

Do you have a specific line of code that's causing it? can you expand the error a bit more?

I don't see much NumberUtil code that would cause an error:

https://github.com/DenisCarriere/turf-jsts/search?utf8=%E2%9C%93&q=NumberUtil&type=

@themre
Copy link
Contributor Author

themre commented Nov 25, 2017

unminified version produces this:

class NumberUtil {
  interfaces_ () {
    return []
  }
  getClass () {
    return NumberUtil
  }
  equalsWithTolerance (x1, x2, tolerance) {
    return Math.abs(x1 - x2) <= tolerance
  }
}

sorry I can't help you much regarding this error, I was looking into rollup docs to see if I can expand debug info, but apparently this needs to be added. perhaps I'm missing something with rollup? https://github.com/themre/leaflet.pm/blob/feature/rollup/rollup.config.js

@DenisCarriere
Copy link
Contributor

Humm.. 🤔 Maybe it's failing because it's a Class? Rollup won't transpile code into ES5 and Uglify needs to have ES5 code which means ES6 classes will break uglify.

@themre
Copy link
Contributor Author

themre commented Nov 25, 2017

I've opened an issue with rollup uglify for someone to check if the issue is with the syntax or somewhere else. Thanks!

@DenisCarriere
Copy link
Contributor

@themre You might want to have a look at rollup-plugin-uglify-es, it won't transpile to ES5, but at least it will run...

@themre
Copy link
Contributor Author

themre commented Nov 26, 2017

awesome job you did @DenisCarriere ! bundle went from more than 500kb to 280 kb. For now I moved those 3 methods from jsts to separate file just to see how your modules behave. here is PR in progress:
#256

codeofsumit added a commit that referenced this pull request Mar 14, 2018
* Fire Circle Edit Event

* added start script

* removal button now respects pmIgnore, fixes #172

* add babel polyfill

* added polyfill to build config as well

* wops, forgot it here 🤔

* added polyfill to fix #173

* removed babel-polyfill

* * More polyfills for IE:
  - Object.assign() is needed for snapping
  - Element.remove() is needed when removing control buttons
* demo.js dumbed down for IE11:
  - IE doesn't understand thoose fancy lambdy style expressions
  - object literals always need a key

* increased version

* 0.17.1

* link to new demo page

* fix #179

* fix #180

* version bump

* 0.17.2

* fixed manual install desc

* fix #182

* removed uncessary if statement

* used setLatlngs to update LInes and Polygons. Hopefully fixes #181

* fixed coord diff from line and poly

* clarified function name

* removed console.log

* added circle toolbar option

* check map drag state before changing it - fix #189

* fix #185

* another demo test

* thing

* updated version

* 0.17.3

* markers are correctly created

* updated gif

* continued

* cursorMarker: true is now default

* Change the source map and minimise the source

* Should be const not var

* fixed the middlemarker position problem

* you can now add markers

* markers can now be removed

* cleanup

* snapping works again 🎉

* Dragging now supports holes

* cleanup

* minor cleanup

* basic drawing works 🎉💪

* map drag fix

* removed test console log

* better comments

* removed console logs

* properly removing cutting events

* prevent pm:remove event from being fired

* splitting polygons works now

* updated demo tiles

* made first map more demo friendly

* handle toolbar button correctly

* fixed typos

* updated leaflet

* updated readme

* 0.18.0

* removed console.log

* FIXED: Vertex Removal removes layer or hole (patch) (#209)

* ADDED: `pm:cut` event (minor) (#211)

* added cut to layerGroup

* fire cut event on map and layer

* updated with cut event info

* added some code comments

* added cutPolygon button to toolbar options

* minor things

* ADDED: Rectangle Support for Drawing and Editing (#196)

* IMPROVED: Rearranged Toolbar and renamed some buttons (patch) (#212)

* rename toolbar buttons, rearrange them, add backwards compatibility

* updated options

* added backwards compatibility with toggleButton

* FIXED: marker edit respects draggable option now (patch) (Fixes #213)

* updated version and added rect desc

* 0.19.0

* updated URL to new demo page

* Make HintMarker more visible (#220) (PATCH)

* hopefully fix #226

* added marker index information to markerdrag events. Fixes #225 (PATCH)

* Removed sourcemaps from prod build. Fixes #222 (PATCH)

* add workingLayer to pm:drawstart (#221) (PATCH)

* add workingLayer to pm:drawstart

* update documentation and demo according to feedback on PR

* minor wording fix

* nothing

* minor webpack optimization

* Added Vertex Events (#227) (MINOR)

* added first demo case

* added pm:vertexadded event to drawing lines and polygons

* added vertexadded and vertexremoved events to Edit class of Line and Polygon

* added documentation

* added syntax highlighting to markdown js 🙄

* Fix error when removing a layer during snappable drawing;
 fixes #208 (MINOR)

* version bump to 0.20.0

* 0.20.0

* centerMarker is not draggable anymore during Circle Draw. Fixes #230 (patch)

* removed console.log

* removed cdnjs button

* - remove extra script tag from demo (#232)

* Added `finishOn` option to pass events on which to finish drawing (#233) (minor)

* add option to pass event name to perform finish of polygon

* update docs

* fix demo example, no event for finishOn

* test

* properly unbind optional listener

* added fallback for finishOnDoubleClick

* added finishOn example

* removed test

* fixed bug in fallback

* prevent zoom when dblclick finishes shape

* added example how options can be passed to toolbar buttons

* fixed encoding error

* stopped the stupid thing of manually entering the versions into the CDN links 🤦‍♂️

* 0.21.0

* Create CODE_OF_CONDUCT.md

* Create CONTRIBUTING.md

* Create LICENSE

* remove license in favor of LICENCE.MD

* Create ISSUE_TEMPLATE.md

* Update ISSUE_TEMPLATE.md

* Update README.md

* better code syntax highlighting

* updated turf and webpack

* Fix 🐛  for switching drawing modes, fixes #242 and other problems (patch) (#240)

* ADDED: `allowSelfIntersection` option (minor) (#241)

* started on it

* kinda works

* nothing

* ok works for drawing

* lots of stuff is working now

* invalid style is resetted on disable

* hasSelfIntersection now works without edit mode

* added code comments

* added README docs

* style is now handled by css class

* fix when vertex removal causes valid poly

* changed invalid style to just stroke

* fixed toolbar bug

* vertexremoved event is now only listened to when allowSelfIntersection is true

* intersection for the cutting polygon is now forbidden

* invalid class is now correctly removed on disable

* handle error when cutting self-intersecting polygons

* resulting layer of cutting now properly inherits options

* just more comments

* added pm:intersect event

* removed console.log

* made cut button snappable by default

* 0.22.0

* added jsfiddle starting point

* fixed some example errors

* added fire, markerdragend and markerdragstart pm events to rectangle. Fixes #245

* removed a console.log

* Added global edit mode toggled event. Fixes #246 (MINOR)

* Added pm:update event. Fixes #229. (MINOR)

* set default _globalRemovalMode to false as promised in #247

* rectangle helpers are hidden when not needed. Fixes #252 (PATCH)

* fix rectangle drawing color bug (#253) (patch)

* Feature/bump deps (#255) (PATCH)

* bump dependencies

* bump dependencies, fix webpack build

* added pm:centerplaced event, fired when the center of a Circle is placed or moved. Fixes #251. (MINOR)

* 0.23.0

* enable babel predets, fix #261 🤞

* minor stuff

* 0.23.1

* added missing step, closes #283

* pm:edit on circles fires after edit, not during. Fixes #285

* hintline style is properly reset after showing error style, fixes #275

* dont start drag on right click, fixes #260

* Redundant coordinate when finish polygon with double click (#281)

* Fixes #147: Redundant coordinate when finish polygon with double click

* Do not remove last vertex on touch interactions since double tap doesn't create an extra vertex.

* demo looks better on mobile now

* minor changes to last PR merge

* add option to disable marker removal during edit. Fixes #258

* eslint fix

* added option to prevent vertex editing in edit mode. Fixes #274

* updated some deps

* Support preferCanvas (#286)

* Added fixes to various modules to account for preferCanvas being set to true on a Leaflet map.

* minor adjustments

* removed comment

* 0.24.0
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.

3 participants