Search code examples
javascriptnode.jsbrowserifyturfjs

Build turf.js with Browserify


I am trying to build a recent copy of turf-buffer which is a module of turf.js. I ran npm install turf-buffer and then browserify turf-buffer/index.js > turf.js. However, upon including the resulting turf.js in the html file (it is definitely there) and calling var buffered = turf.buffer(originalData, buf, 'meters'); I get the message turf is not defined. I have also tried turfjs.xxx, turf-buffer.xxx and various other combinations. If I try turfxxxx.yyy then I still get turf is not defined which suggests a fundamental turf object is missing. I presume this is a problem with the browserify build. Is there a flag I need to give to browserify or could it be a lack of package-specific instructions?


Solution

  • I've fixed it - I needed to specify an entry point (not sure if that is the right term) by using -s, so the final command was browserify turf-buffer/index.js -s turf.buffer > turf.js.