Unnecesary dependencies brought along with jsts-es
See original GitHub issueIn modules @turf/buffer
, @turf/difference
, @turf/intersect
and @turf/union
, modules from jsts-es
are imported from the main module. E.g. in turf buffer:
import { BufferOp, GeoJSONReader, GeoJSONWriter } from 'jsts-es';
It turns out that in jsts-es/index.js
, when every submodule is exported
export * from './src/org/locationtech/jts/geom'
export * from './src/org/locationtech/jts/algorithm'
export * from './src/org/locationtech/jts/densify'
export * from './src/org/locationtech/jts/dissolve'
export * from './src/org/locationtech/jts/geomgraph'
export * from './src/org/locationtech/jts/index'
export * from './src/org/locationtech/jts/io'
export * from './src/org/locationtech/jts/noding'
export * from './src/org/locationtech/jts/operation'
export * from './src/org/locationtech/jts/precision'
export * from './src/org/locationtech/jts/simplify'
export * from './src/org/locationtech/jts/triangulate'
export * from './src/org/locationtech/jts/linearref'
there are side effects that result in the whole (or most part) of jsts-es
being brought along the required modules.
If I build @turf/buffer
using rollup to ES6 module output, the final size is 898K and the module includes (for example), JSTS definitions for classes (to name a few) DouglasPeuckerLineSimplifier
, MonoValentEndPointBoundaryNodeRule
, ConformingDelaunayTriangulationBuilder
, and many more that are not used at all by the Buffering operation.
If I instead require the modules directly as:
import GeoJSONReader from 'jsts-es/src/org/locationtech/jts/io/GeoJSONReader.js';
import GeoJSONWriter from 'jsts-es/src/org/locationtech/jts/io/GeoJSONWriter.js';
import {
BufferOp
} from 'jsts-es/src/org/locationtech/jts/operation/buffer.js';
The bundle size drops to 515Kb
Now, I don’t know if this is due to my rollup.config.js
being misconfigured, But I’m pretty convinced this is because JSTS structure is somehow breaking Rollup’s tree shaking.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
JSTS has big problems when making it ES Module & CJS compatible.
The other major issue I found was the
extend()
method that JSTS uses copies the entire section of that source code. For example if we have 4 Turf modules that use JSTS, that means we will have 4x GeoJSONReader source code in the final Rollup bundle.To solve this, I’ve been working on refactoring JSTS for the sole purpose of importing it in TurfJS.
https://github.com/DenisCarriere/turf-jsts
Once it’s complete I’ll replace the
jsts-es
module with that new code base.We’re on turf-jsts at this point, going to close this ticket out.