SINTEF-9012 / PruneCluster

Fast and realtime marker clustering for Leaflet
MIT License
551 stars 131 forks source link

Webpack, AMD, CommonJS... which one are you using? #115

Open lamuertepeluda opened 8 years ago

lamuertepeluda commented 8 years ago

I'm having troubles importing PruneCluster into my webpack project. None of these is working! Always undefined. It seems like the library does not follow any convention, while Leaflet does.

//ES5 style
var PruneCluster = require("prunecluster/dist/PruneCluster.js");
//ES6 with Babel
import {PruneCluster, PruneClusterForLeaflet} from "prunecluster/dist/PruneCluster.js";
//hoping to find some default
import "prunecluster/dist/PruneCluster.js";

Leaflet

import L from "leaflet/dist/leaflet-src.js";

I guess you should do something about it...

lamuertepeluda commented 8 years ago

By the way a found a solution by myself but it's more an hack that puts the issue in evidence:

import L from "leaflet/dist/leaflet-src.js";

var PruneCluster = require("imports?L=leaflet/dist/leaflet-src.js!exports?PruneCluster!prunecluster/dist/PruneCluster.js");

I found out this by reading this docs.

However there would be no need if you stick to some standard module definitions.

fungiboletus commented 8 years ago

Hi,

module.exports or define are not supported and undefined on web browsers, as far as I know. If you look at Leaflet's source code, it contains specific code to support AMD or CommonJS module definitions.

We could add support for AMD or CommonJS the same way Leaflet does, a PR is welcome.

lamuertepeluda commented 8 years ago

That's correct: there is some additional code required to support module definition, just like Leaflet does. However there are obvious advantages when integrating the library in a wider project.

Also UMD is an option.

I'll see what I can do, given that I'm not familiar with TypeScript at all, in order to make a PR.

danvirsen commented 7 years ago

Any updates on this?

fungiboletus commented 7 years ago

It's on the TODO list.

ghost commented 7 years ago

Using webpack export loader, add this line to your javascript.

import { PruneCluster, PruneClusterForLeaflet } from 'exports-loader?PruneCluster,PruneClusterForLeaflet!prunecluster/dist/PruneCluster.js'

disarticulate commented 6 years ago

@gtanguay may not be obvious to some:

npm install exports-loader --save-dependency
pedroetb commented 2 years ago

Any update on this? I have been using the fork proposed at #161 pull request since 2018.

fungiboletus commented 2 years ago

Hei @pedroetb This project has been on pause for a few years, mostly because I left the company and no one took over.

I hope to resume the development at some point and modernize it, but I cannot give a timeline because I don't have a budget for that yet.

Things has changed with now MapBoxGLJS/MapLibre or Deck.gl. Meanwhile you can continue to use the fork if it still work.