-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use other libraries in your library (besides React and React-dom) #53
Comments
@reinrl thanks for this issue, i'll add those instructions in readme 👍 |
I created a few different sample projects, using this project as a starting point - and I always seem to run into errors whenever attempting to bundle other libraries within mine (e.g., I want be dependent a form library, but don't want to force that dependency on a consuming application by using a devDependency/peerDependency combination). As I had noted in issue DimiMikadze#53, using libraries which I want to force the consuming application to specify a dependency on is relatively trivial (add to devDependency/peerDependency in my library, and add to the "externals" configuration within your webpack.config file(s). In this particular case, I couldn't find a way to simply bundle another library without having to go that route - until I realized that I needed to add to the webpack output config (a libraryTarget attribute had already been added, but I needed to also specify library and umdNamedDefine attributes before this all worked for me). Now, I can simply add internal dependencies to my package.json's dependency array, and my consuming application is none the wiser.
I am not sure I follow the explanation. I also have this issue right now when I am trying to download the library I have built from npm and it fails to compile because
I still can't build successfully and I dont want to add it as peed dependencies because its just another thing for the use to think about. Am I missing something? UPDATEthis solution works (: |
So you did get it to work? With my change, or was there more to it? |
Hmm, your change not worked for me. I added the libraries as regular dependencies suggested in the comment above and it worked. I didn't removed the changes I made in webpack those so it might be a combination of those solutions. So at the end I have:
and it works (: |
I am not at a computer right now, so I will have to doublecheck my working local stuff later, but basically here is the difference:
|
So after more struggle, I realised it should be a combination of adding the libraries you want to use into |
Admittedly, my local examples are a bit different from what originally came from here, so this might be right or it might be wrong (some of the changes I made were for other reasons) - but you didn't have to have a given dependent library listed in your regular npm dependencies unless you want your library to package/bundle it for the consumer...and you shouldn't have to have a given dependent library listed in your webpack externals unless you intend it to be a peer dependency provided by your calling app (like react/react-dom). In your webpack.config.js, find the keywork libraryTarget (the full line should look something like libraryTarget: (isEnvDemo || isEnvProduction) ? 'umd' : undefined,), and make it look like this:
The library and umdNamedDefine bits are new. Once you have added those in, try removing anything from your externals that is not truly a peer dependency (but leave them in your dependencies). Assuming that that corrects the issue, it should be able to be added to the patch above. |
After a long day of chasing my tail, I have a suggestion for adding some additional information to the documentation/examples/somewhere (in case it helps someone else too).
If you are creating your own library using this as your boilerplate (such as the "under construction" example), and you want to make use of another library within yours, consider the following:
As a helpful aside, also make sure to add any peer dependency expectations to your readme.md - that way, people making use of your new shared library will understand what dependencies they need to install/already have available.
The text was updated successfully, but these errors were encountered: