aws-geospatial / amazon-location-utilities-datatypes-js

Utilities to translate geospatial data types used by Amazon Location from / to well-known geospatial data types such as GeoJSON.
Apache License 2.0
3 stars 4 forks source link

Use rollup + babel to generate to javascript code #15

Closed eashuang closed 1 year ago

eashuang commented 1 year ago

Hi, I have tried to use rollup + babel to generate bundled javascript code for distribution.

Description of changes:

  1. Update build target to
    1. Use tsc to generate type declarations to dist
    2. Use rollup and babel to generate 3 bundles
      1. dist/es/index.js: Javascript supporting esm.
      2. dist/js/index.js: Javascript supporting cjs.
      3. dist/index.js: Browser compatible Javascript.
  2. Modify package.json so above files are used when importing our package.
  3. Modify the build workflow to run build target instead of build:types
  4. Change tsc target to es2017 so our code and major dependency (turf) are targeting the same ES version.

Generated artifacts

dist
├── es
│   ├── index.js
│   └── package.json
├── from-geojson
│   ├── geofence-converter.d.ts
│   └── index.d.ts
├── index.d.ts
├── index.js
├── js
│   └── index.js
└── to-geojson
    ├── device-position-converter.d.ts
    ├── geofence-converter.d.ts
    ├── index.d.ts
    ├── place-converter.d.ts
    ├── route-converter.d.ts
    └── utils.d.ts

Tests I have tested it only takes 2.5s on my machine to generate 3 bundles with rollup + babel. I have also tested following:

  1. Create a cjs dependent and require our package, calling an exported function.
  2. Create a esm dependent and import one of our function, calling it.
  3. Create an index.html including dist/index.js, calling an exported function.
  4. Create a typescript dependent, import one of our function and see if the type get populated correctly in my IDE (WebStorm)

Please help review and feedbacks are appreciated :)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.