Search code examples
javascriptnode.jsclojurescriptfigwheel

Use Node.js library from ClojureScript project


I'm trying to use a Node.js based component (https://github.com/leandrowd/react-responsive-carousel) in my Figwheel-based ClojureScript app.

Unfortunately I cannot find a "standalone", packaged Javascript file with react-responsive-carousel. Since my app is not run by Node.js, it cannot require etc.

Is there either an elegant way to reuse Node.js libraries from ClojureScript, or a solution to package any Node.js library into a standalone file?


Solution

  • You can use Webpack to turn the library and all its dependencies into a single JavaScript file which exports a reference for the library. In carousel-module.js

    global.Carousel = require('react-responsive-carousel').Carousel;
    

    Check out the Webpack page for how to set up Webpack.

    It's unfortunate that we still have to go through this convoluted method to use CommonJS libraries. I hope native support is coming soon.