2016-10-24 5 views
2

私はこのプロジェクトangular2-google-maps-testに構築し、私は含めると、これはJS拡張していないようlibにjs-marker-clustererあなたには、どうすればよい/ロールアップ、typescriptですとJS libにを拡張し、angular2

npm install --save js-marker-clusterer

moduleと書かれています。

私はこのような何かやりたい
function MarkerClusterer(map, opt_markers, opt_options) { 
    // MarkerClusterer implements google.maps.OverlayView interface. We use the 
    // extend function to extend MarkerClusterer with google.maps.OverlayView 
    // because it might not always be available when the code is defined so we 
    // look for it at the last possible moment. If it doesn't exist now then 
    // there is no point going ahead :) 
    this.extend(MarkerClusterer, google.maps.OverlayView); 
    this.map_ = map; 
... 

} 
window['MarkerClusterer'] = MarkerClusterer; 

// js-marker-clusterer.d.ts file 
declare module "js-marker-clusterer" { 
    export class MarkerClusterer { 
    constructor(map: any, opt_markers?: any, opt_options?: any); 
    map_: any; 
    markers_: any[]; 
    clusters_: any[]; 
    ready_: boolean; 
    addMarkers(markers: any[], opt_nodraw: boolean) : void; 
    removeMarker(marker: any, opt_nodraw: boolean) : boolean; 
    removeMarkers(markers: any[], opt_nodraw: boolean) : boolean; 
    } 
} 

をして、typescriptです

/// <reference path="./js-marker-clusterer.d.ts" /> 
export class MyMarkerClusterer extends MarkerClusterer { 
    constructor(map: any, opt_markers?: any, opt_options?: any) { 
    super(map, opt_markers, opt_options); 
    } 
} 

にそのクラスを拡張するが、rollupjsに、私はこのエラーを取得しておいてください。

[21:20:47] bundle failed: 'MarkerClusterer' is not exported by node_modules/js-marker-clusterer/src/markerclusterer.js MEM: 469.6MB 
      (imported by src/angular2-marker-clusterer/my-marker-clusterer.ts). For help fixing this 
      error see https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module 

私の推測はrollup.config.jsファイルに何かを追加する必要がありますが、私はpluginとして追加しようとしましたが、うまくいきませんでした。

/** 
    * plugins: Array of plugin objects, or a single plugin object. 
    * See https://github.com/rollup/rollup/wiki/Plugins for more info. 
    */ 
    plugins: [ 
    builtins(), 
    //commonjs(), 
    commonjs({ 
     namedExports: { 
     'node_modules/angular2-google-maps/core/index.js': ['AgmCoreModule'], 
     'node_modules/js-marker-clusterer/src/markerclusterer.js': ['MarkerClusterer'] 
     } 
    }), 

答えて

0

実は、私は活字体の一部については知らないが、私が代わりにあなたがrollup-plugin-legacyを試してみてくださいプラグインcommonjsを考えます。

legacy({ 
    'node_modules/js-marker-clusterer/src/markerclusterer.js': 'MarkerClusterer' 
}) 

インポートステートメントを適宜変更してください。