tyrasd / osmtogeojson

convert osm to geojson
http://tyrasd.github.io/osmtogeojson/
MIT License
683 stars 112 forks source link

es6 module #108

Open backspaces opened 5 years ago

backspaces commented 5 years ago

This is a request for an es6 module version of osmtogeojson.

Fortunately, rather than porting the index.js to es6, rollup, with a cjs plugin, does the trick!

This config file will convert osmtogeojson to an es6 module:

import commonjs from 'rollup-plugin-commonjs'

export default {
    input: './node_modules/osmtogeojson/osmtogeojson.js',
    output: {
        file: 'dist/osmtogeojson.esm.js',
        format: 'es',
    },
    plugins: [commonjs({})],
}

So you'd need to add rollup and rollup-plugin-commonjs to your devDependencies, adjust the input/output paths (you may prefer the osmtogeojson.mjs node preference suffix), and add a npm build script for "rollup -c "

You can also add

"module": "<path to osmtogeojson.mjs>",

to package.json (under the "main" property is good) so that CDNs like unpkg.com can find it with the "?module" flag.

I use this rollup in my all-module repo for osmtogeojson now for in-browser use and it seems to work .. I'll get back to you if I discover any problems.

You can convert the repo to es6 later if you'd like, using rollup to create a UMD (good for both node require() and browser script tag) from your es6 module. It would be a non-breaking change if you keep the file names the same.