2

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?

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I actually used Browserify in a similar way. I second you: it would be so great to be able to do everything from project.clj.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.