0

I have a library I am writing. My library is build using rollup.

I want to include it in my main application. The app is built using create-react-app.

I would like to use the dev version of the library in the app without publishing it to the npm registry. It becomes more so painful to publish and use. (even with local repositories like local-npm) because a version can be published only once. I have seen the hack provided here - Using SNAPSHOT in private NPM like in Maven

I tried to use the npm link. Apparently, CRA will not use the dep if the real path is outside of the base folder even if a symlink is present.

What is the best way of handling the situation? I want to set this up as a precedent for all my future app work and am looking for a solution as well as a best practice I can adhere to.

user1676688
  • 414
  • 4
  • 15

1 Answers1

0

I do not know the best way to do it but your problem is the same with mine when I have to include a js SDK file to my CRA project.

Inside the index.js file, just import it.

import "./libs/latest.sdk.bundle.min";

const something = new ClassFromSDK();

something.func();

Generally

  • You write a class from your js file and inside this class, you should have some functions that you need to use.

  • Store this file in your project like src/libs/mylib.js

  • Import it to the root CRA file (index.js) like above.

  • After initiating a instance of this class, just use the function inside as usual.

thelonglqd
  • 1,805
  • 16
  • 28
  • What are you doing to get the output of the build in the lib directory? Are you manually copying it over after building the library? – user1676688 Dec 31 '20 at 07:46
  • just like normal ultilities class inside your project. If your file is js, you will get the production build output when run `npm run build`. Do I missed something from you ? My assumption is `rollup` is irrelevant here. You have a bunch of JS code in a js file and you want to add it to CRA, right ? – thelonglqd Dec 31 '20 at 07:53
  • 1
    Nah. I am saying that I am working on 2 projects simeltaneously. One project depends on other. The rollup output will have to be consumed in my CRA project. There alternatives like using lerna or creating a monorepo that I do not want to do. Keep the builds independent – user1676688 Dec 31 '20 at 08:29