digidem / react-mapfilter

Visualizing, exploring, filtering and printing geographic data and geotagged photos and video
https://lab.digital-democracy.org/mapfilter
29 stars 11 forks source link

Build for npm publish #61

Closed gmaclennan closed 7 years ago

gmaclennan commented 7 years ago

Trying to build and package for publishing npm.

Right now the packaged version does not work without babelify, gives the following error:

Cannot find module '../core-js/object/define-property' from '/Users/gregor/Dev/DdDev/mapfilter-new/dist'

We a single export from this module when it is published to npm: The React Component <MapFilter> that works without babel or anything else.

mojodna commented 7 years ago

Now intended to publish ES5 artifacts (es5/*, transpiled with babel) suitable for require() / import.

Demo: https://github.com/mojodna/mapfilter-demo

mojodna commented 7 years ago

For posterity, the source of the initial symptom was that browserify was correctly bundling everything (including React, which would have led to further problems down the line). It stubbed out require(), so including mapfilter.js in a <script> tag worked. However, when used in an environment where require() actually existed (such as an environment built with browserify or just plain node), it would defer to that. babel-runtime/helpers/defineProperty.js does a relative require of ../core-js/object/define-property, which fails to resolve appropriately in the new environment.

derequire addresses the relative require problem, but then there were [app-specific] CSS inlining problems.

mojodna commented 7 years ago

@gmaclennan:

If/when we do, for people that like script tags, https://www.bram.us/2016/08/04/distributing-your-react-component-as-a-standalone-version/ is what we need.

(build:js will likely get us partway there)