javascriptes6-modulesunpkg

Import d3 from unpkg


I would like to import d3 from unpkg.com but I am not sure which file I should be importing. What would be the unpkg equivalent of:

import * as d3 from "d3";

Solution

  • This will import d3 globally:

    import 'https://unpkg.com/d3@6.2.0';
    
    // D3 defined globally
    d3.select(...);
    

    This will import it as a module (but make a lot of network requests for each module :/)

    import * as d3 from 'https://unpkg.com/d3@6.2.0?module';
    

    Src: https://twitter.com/unpkg/status/905239560988221440