0

I have some legacy code which uses D3 and is compiled with webpack. I'm toying with the idea of porting the D3 bits as external library, and wrapping them as a reagent/re-frame component, yet I have problems importing the JS bits.

I created a small project which demonstrates the problem:

  • The JS library code .
  • The webpack config used to (UMD) compile it.
  • The compiled library (without minify for readability).

Now in a JS project I would use the library like this:

import * as module from 'd3-lib.js'

var m = new module.Module()

m.setData("miserables.json").render();

I tried to mimick that:

Yet I keep getting:

Uncaught Error: goog.require could not find: d3_lib

fbielejec
  • 3,492
  • 4
  • 27
  • 35

1 Answers1

0

Have you tried to use the d3 package from cljsjs ?

Using the cljsjs/d3 package

Add the dependency coordinates [cljsjs/d3 "4.3.0-5"] to the list of :dependencies in your project. Make sure to require cljsjs.d3 somewhere in your project so it is added to your compiled ClojureScript code.

(ns your.namespace (:require [cljsjs.d3]))

You can now use your newly added library by accessing it through the global Javascript namespace, e.g.js/ReactPlease check the project's documentation to find out what global the library uses. Please note: You can not use :as or :refer with CLJSJS dependencies.

Nicolas Modrzyk
  • 13,961
  • 2
  • 36
  • 40
  • Hi Nicolas, thank you for your answer. I am aware of the CLJS project and the concept of externs, yet the situation here is a bit different - the webpack library (d3-lib) is already compiled with webpack i.e. it contains the D3 bits (stripped of unused code - see the third URL I posted in my question). It's supposed to act as a self-contained vizualisation (with fluent API) ready to be plugged-in in cljs or node.js project (the example I posted off course is minimal, the library in fact is a lot bigger, but the concept stays the same). – fbielejec Jul 04 '17 at 08:47