-
Notifications
You must be signed in to change notification settings - Fork 129
Conversation
this pr also changes some code to make compatible with the browser. It exposes the global variable "carto" One of the problems is mapnik reference, the module is not read to work with browserify since it loads modules dynamically. It does not make sense to make it compatible since mapnik-reference is not going to be used so people must to set the reference needed before parse/render: carto.tree.Reference.setData(reference)
If we're going to support browserify, we should only export as a module, and never touch globals without permission.
I'm not comfortable papering over this problem by deferring the failure to whenever someone calls a documented API.
This should use Why does this require a listing of all Basically: If we want to support browserify, a proper module compatibility should come first, not a bundled standalone build. |
this build is created to work in a browser, it's a common pattern to expose global scope to use it in javascript, maybe there should be a build specifically for it ?
basically that is a workaround for carto being attached to mapnik-reference, what do you propose?
because of this dynamic loading: https://github.com/mapbox/carto/blob/master/lib/carto/index.js#L67
not sure if a follow you here, what is exactly "a proper module compatibility" ? |
Okay, so that shouldn't be dynamic - right now we're trading a bit of brevity for browserify compatibility, let's trade back.
Browserify is here to make var carto = require('carto'); Work: to make CommonJS modules usable as modules in the browser.
Making mapnik-reference work with browserify. It's possible.
To make a standalone build, you should be able to do this: npm install carto
browserify -r carto -s carto > carto.standalone.js But by default you should use carto as a module: in your package.json, with a commonjs include: the default way to use modules with browserify. |
browserify is here to make standalone modules too.
Yep, the thing here is carto should not depend on mapnik-reference thanks for your time man |
Just to be clear: I agree, and it's totally possible to disentangle the two. |
adds support for browserify, the final javascript file can be generated using make target:
It exposes the global variable "carto" so can be used in the browser like:
One of the problems is mapnik reference, the module is not read to work with browserify since it loads modules dynamically. It does not make sense to make it compatible since mapnik-reference is not going to be used so people must to set the reference needed before parse/render:
carto.tree.Reference.setData(reference)
this PR also changes some code to make compatible with the browser.