Skip to content
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

Creating npm projects/modules #2978

Closed
piernik opened this issue Nov 1, 2016 · 23 comments
Closed

Creating npm projects/modules #2978

piernik opened this issue Nov 1, 2016 · 23 comments

Comments

@piernik
Copy link

piernik commented Nov 1, 2016

By default angular-cli creates application (with index.html and all js files). The question is how to, using angular-cli, build npm modules/projects?

I want to create separate modules that I can use in other projects.
Is there some kind of roadmap or tutorial how to build modules to be published on npm?

@piernik
Copy link
Author

piernik commented Nov 2, 2016

Anyone can help with it?

@deebloo
Copy link
Contributor

deebloo commented Nov 3, 2016

@piernik this issue has come up a couple of times. At the moment you will have to do some of your own tooling to get something ready to be published to npm.

@piernik
Copy link
Author

piernik commented Nov 3, 2016

I see. Hope it will be included very soon. Thanks for response.

@clydin
Copy link
Member

clydin commented Nov 3, 2016

@piernik, you can check out angular/material2 for an example of a working library.

@thatchej
Copy link

thatchej commented Nov 3, 2016

Struggling hard with this as well, +1 for requested feature. If angular-cli did this natively my life would be wonderful right now

@thatchej
Copy link

thatchej commented Nov 3, 2016

@deebloo any recommendation in tooling setup? not sure exactly what to deliver to consuming apps

@deebloo
Copy link
Contributor

deebloo commented Nov 3, 2016

So right now for work we have several separate libs we created with the cli. We are only worried about consuming via typescript so I just included an index.ts file at the root of the repo that exports the desired pieces and then install from github. That is working really well for us.

@thatchej
Copy link

thatchej commented Nov 3, 2016

@deebloo Pardon the questions but I've been working on this for a few days to no avail :)

1.) Do you compile the project before you bring it in as a dependency or do you let the master project take care of that?

2.) Are you bringing it in as an npm dependency or are you cloning the repo locally into the master project?

@deebloo
Copy link
Contributor

deebloo commented Nov 3, 2016

@thatchej no worries at all.

1.) right now we just leave everything as typescript and let the master project handle the compiling.
2.) I am using npm to manage the dependencies but and just installing from github.

so steps to manage:
1.) put index.ts file in the root and export stuff
2.) commit project to github and tag
3.) install in other other project.

dependencies: {
    "my-core": "github:username/repositoryname#v1.0.1"
}

This is working well for use for internal libs and such but isn't feasible for public libs and such. Hope this helps!

@thatchej
Copy link

thatchej commented Nov 3, 2016

Cool, the index.ts file may be the key I am missing. Right now I am pretty much doing the same thing without it, and continue to get some real weird error messages like TypeError: ngModule is null when I try to import.

I'm trying a much more basic strategy with a very simple angular project hand compiled to .js and typing files, but if this falls on it's face I'll definitely try your strategy

@deebloo
Copy link
Contributor

deebloo commented Nov 3, 2016

@thatchej let me know how it ends up working for you. I am working on some tooling to help with this that could be used alongside the cli but not ready yet.

@bthharper
Copy link

Really interested in the ability to do this too, I'm trying to hand craft this at the moment.

I am trying to avoid using lots of relative paths, and would like something like

import { MyComponent} from "@mypackage/core";

I've tried using paths and baseUrl in tsconfig, but this causes other problems.

@deebloo is there any chance you could give me some pointers on how you import your modules/components into the hosting project?

@deebloo
Copy link
Contributor

deebloo commented Nov 3, 2016

@bthharper if you install them with npm you can just import them as you would any other node module

@bthharper
Copy link

@deebloo Just realised how stupid I was being ... works a treat!

@thatchej
Copy link

thatchej commented Nov 3, 2016

@deebloo I've now tried both strategies and continue to get the same issue. It seems to specifically be that the two different versions of Angular 2 are clashing (the master projects version, and the library component version). How are you avoiding this?

@deebloo
Copy link
Contributor

deebloo commented Nov 3, 2016

@thatchej peer dependencies

@thatchej
Copy link

thatchej commented Nov 3, 2016

@deebloo how do I set that up? it's not something I've touched yet

@deebloo
Copy link
Contributor

deebloo commented Nov 3, 2016

@thatchej there is just a property in your package.json file called peerDependencies. https://nodejs.org/en/blog/npm/peer-dependencies/

@piernik
Copy link
Author

piernik commented Nov 4, 2016

I've managed to publish my project to npm.
Here's what I did.

In angular-cli project my module went to single folder (component-warpper).
In that folder I've added index.ts with list of modules and components to export.
I also added package.json file.
Then in command line go to this folder and npm publish.
Now I can import it as node_modules in other projects.

npm-publish

@BernhardRode
Copy link

@piernik you just made my day ;)

@clydin
Copy link
Member

clydin commented Nov 4, 2016

If these are internal libraries, it's generally better to install from github (as @deebloo suggested). Especially if the libraries are typescript only.

@filipesilva
Copy link
Contributor

Heya all, this thread has very nice advice to get libs working right now but I really do have to close it as a dupe of #1692. If I don't conversations will start to diverge instead of being focused in a single thread.

Do add your advice there (that issue is marked as FAQ as well), but I want to say that we're looking at really making libs a first class citizen with the CLI, ready to push compiled libs to npm. Don't have a timeline, but that's the plan.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants