I'm currently developing an Angular 4 app, as part of the work I'm developing a component library that I would like to use in different Angular projects in the future.
Think of it as a set of UI components (e.g. ngx-bootstrap).
After looking into it for some time, it seems like the most common convention is to separate the work into two projects, as well as build them separately. Then, when loading the said component library, we'd load an already compiled version of it.
I would like to avoid having to build the projects separately, and simply have the external library be built together with the parent one, BUT I need the component library to sit outside of the Angular project.
Example for the desired filetree:
Angular Project/
- node_modules/
-- myComponentLibrary // This is a symlink to the myComponentLibrary directory
myComponentLibrary/
- index.ts
- myComponentLibrary.module.ts
It's important for me to have a similar result to that, because the library will be developed during the development of the said Angular project, but also outside of it. Having the npm link
would be nice and easy because webpack notices changes within and rebuilds the project right away, also, it wouldn't require me to build the library beforehand.
What I tried doing, was to use 'npm link' to some external library that I have on my machine, it worked when I used Angular CLI, but I ran into problems when using it with a webpack powered project. When I read online, it seems like it's a complete nono to do so.
Source: http://ift.tt/2y2RMx0
The main problem was post compilation, when visiting the app via the browser, there was an error in the console: "Uncaught Error: Unexpected value 'myComponentModule' imported by the module 'AppModule'. Please add a @NgModule annotation."
The strange thing is that when copying the "myComponentLibrary" directory directly into the node_modules
directory, it worked. But with a symlink
/ npm link
it just doesn't seem to work.
What I'm here for is to understand how this functionality is usually achieved.
But building the two projects separately will be my very last resort as it is just too much of a headache as the work on those two projects is so parallel.
Aucun commentaire:
Enregistrer un commentaire