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

es6 module #108

Open
backspaces opened this issue May 5, 2019 · 0 comments
Open

es6 module #108

backspaces opened this issue May 5, 2019 · 0 comments

Comments

@backspaces
Copy link

backspaces commented May 5, 2019

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.

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

No branches or pull requests

1 participant