Closed helllth closed 6 years ago
We do publish pre-compiled packages in the @turf/turf
library under turf.js
& turf.min.js
. At the moment it's still on v5.0 (turf-jsts
will be published under v5.1).
- If the dependency is small enough, copy it to your src/ folder and treat it as application code.
For now that could be an option for your use case.
@helllth If you want to weigh in on this PR https://github.com/Turfjs/turf/pull/1131, I'm currently trying to publish Web Bundle, CommonJS & ES Modules using only Rollup + Babel (hopefully this can work for TurfJS's pre-compiled package).
Thanks for your quick answer 😄
Unfortunately a copy of the turf.min.js
in my src
lead to other problems. But a Babel transpiling of https://github.com/DenisCarriere/turf-jsts helped. (I downgraded the import to import intersect from '@turf/intersect';
which is at the moment the only problematic import.)
Would it be an option to release that project (turf-jsts
)with a pre-compiled package?
👍 Let me look into republishing turf-jsts
I've also had some issues with it last night.
Right now the only pre-compiled package is the Module, but not the CommonJS file, so maybe that's why it's causing an issue?
Unfortunately the release of 1.0.1 didn't help.
(With the Link to additional info I posted earlier.)
I will setup a minimal example project that reproduces the error and go on with the "babeled" version in the meantime.
@helllth seems like react-scripts build
is using the module: index.js
instead of main: jsts.js
... 🤔
Please post a minimal example I can include in turf-jsts
that will test for this build.
@helllth I've got new Errors now, I've copied turf.js
and placed into the repo.
Unfortunately, these errors are from the poor original code, there was a few things missing which I chose to ignore when doing the refactoring to ES6.
I guess I'll have to fix those as well to make the build pass.
$ react-scripts build
Creating an optimized production build...
Failed to compile.
./src/jsts.js
Line 345: 'CloneNotSupportedException' is not defined no-undef
Line 3396: 'UnsupportedOperationException' is not defined no-undef
Line 4011: 'IllegalStateException' is not defined no-undef
Line 4162: 'NumberFormatException' is not defined no-undef
Line 4163: 'NumberFormatException' is not defined no-undef
Line 4168: 'NumberFormatException' is not defined no-undef
Line 6334: 'javascript' is not defined no-undef
Line 7320: 'IllegalStateException' is not defined no-undef
Line 7391: 'IllegalStateException' is not defined no-undef
Line 9736: 'IllegalStateException' is not defined no-undef
Line 11044: 'UnsupportedOperationException' is not defined no-undef
Line 13098: 'IntersectsOp' is not defined no-undef
Line 14119: 'IllegalStateException' is not defined no-undef
Line 16910: 'IndexOutOfBoundsException' is not defined no-undef
Line 17654: 'Long' is not defined no-undef
Line 22093: 'UnsupportedOperationException' is not defined no-undef
Line 25583: 'IllegalStateException' is not defined no-undef
Line 26878: 'IntersectsOp' is not defined no-undef
Search for the keywords to learn more about each error.
Yes, that`s what I meant with
lead to other problems
:wink:
@helllth 😡 ... After many linting edits (50+ files had issues), I think I've got it!
I've added a script that will test create-react-app
inside turf-jsts
.
A few warning errors left, but it shouldn't prevent you from doing a build:
$ npm run create-react-app
> turf-jsts@1.0.1 create-react-app /Users/mac/Github/turf-jsts
> react-scripts build
Creating an optimized production build...
Compiled with warnings.
./src/java/util/TreeMap.js
Line 157: Unexpected assignment within a 'while' statement no-cond-assign
Line 172: Unexpected assignment within a 'while' statement no-cond-assign
./src/org/locationtech/jts/geom/Coordinate.js
Line 72: Expected a default case default-case
Line 154: Unexpected mix of '^' and '>>>' no-mixed-operators
Line 154: Unexpected mix of '^' and '>>>' no-mixed-operators
Search for the keywords to learn more about each warning.
To ignore, add // eslint-disable-next-line to the line before.
File sizes after gzip:
84.03 KB (+18 B) build/static/js/main.24996049.js
The project was built assuming it is hosted at the server root.
To override this, specify the homepage in your package.json.
For example, add this to build it for GitHub Pages:
"homepage" : "http://myname.github.io/myapp",
The build folder is ready to be deployed.
You may serve it with a static server:
yarn global add serve
serve -s build
@helllth Let me know if it works on your side, I've published a new minor release v1.1.0
🛌 time
I will test it ASAP.
First of all. Thanks a lot for your help. 🥇
I can confirm that the react-scripts build
on the turf-jsts
project works now.
However, in my setup (project with @turf/intersect
as a dependency) the command react-scripts build
still leads to en error.
It looks like the react-scripts build
doesn't use the precompiled stuff and goes down the src
folder for "building".
However if I change the package.json
from:
{
"name": "turf-jsts",
"description": "A JavaScript library of spatial predicates and functions for processing geometry",
"version": "1.1.0",
"main": "jsts.js",
"module": "src/index",
"jsnext:main": "src/index",
"unpkg": "jsts.min.js",
"jsdelivr": "jsts.min.js",
.
.
.
to
{
"name": "turf-jsts",
"description": "A JavaScript library of spatial predicates and functions for processing geometry",
"version": "1.1.0",
"main": "jsts.js",
"module": "jsts.js",
"jsnext:main": "src/index",
"unpkg": "jsts.min.js",
"jsdelivr": "jsts.min.js",
.
.
.
or even delete the line with "module": "jsts.js",
the react-scripts build
command works :thinking:.
I am wondering if that has any downsides?
Humm.. 🤔 ... Well there's one more thing I can do is to build an ES Module pre-compiled repo for turf-jsts
.
Let me publish a new release with a jsts.mjs
file for "module": "jsts.mjs"
That would be great. (At the moment the Version ist still on 1.1.0
)
Every new release I refactor more and more, right now it's broken 🤣
@helllth v5.1
release seems to work for me now using create-react-app
.
If you only need 1 or two modules, I would recommend you import them directly from the module name instead of using @turf/turf
since Webpack can't seem handle the Tree Shaking by default (maybe with extra configurations).
index.js
import { greatCircle } from '@turf/turf';
greatCircle([0, 0], [100, 10]);
$ npm t
> create-react-app@ test /Users/mac/Github/turf/builds/create-react-app
> react-scripts build
Creating an optimized production build...
Compiled successfully.
File sizes after gzip:
136.82 KB (+132.05 KB) build/static/js/main.4ca90ea3.js
The project was built assuming it is hosted at the server root.
To override this, specify the homepage in your package.json.
For example, add this to build it for GitHub Pages:
"homepage" : "http://myname.github.io/myapp",
The build folder is ready to be deployed.
You may serve it with a static server:
yarn global add serve
serve -s build
In order to use your nice library with the
create-react-app
tool it would be nice if you could add pre-compiled packages.See also: https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#npm-run-build-fails-to-minify
This is the case at least for modules that need the
turf-jsts
dependency.