How to create an AngularCli application that conta

2019-04-10 12:16发布

问题:

I have an application in development that is in Angular2 using AngularCli, and I want to use it as a "Layout" (like a MasterPage) to another project. Like a big "SPA System".

For example, in the menu we will have the following:

  • Framework
    • Page A
  • Xpto
    • Page B

The Framework is running in http://localhost:90 and XPTO is running in http://localhost:91. Both of them is running on AngularCli.

I want to create a structure that when I click on Page A or Page B, the browser doesn't reload and it will give an "app" style to the user, loading the page as a SPA ACROSS the sites.

The main reason is to reuse the Javascripts, CSS and many other files from de "Framework" project to other 20 projects. I don't want to replicate all the components, files and etc across those projects.

Today we use MVC3 and the RazorGenerator to create .cshtml as a DLL to reuse the .cshtml from Framework to other modules.

But we want go AngularCli. Is there any way to do that ? If it isn't, is there some way to create a template in AngularCli that can be reused the components and the other files ?

Thank you !

回答1:

You can put shared Angular components and modules into a separate npm package and use this package as a dependency for other projects. In order to reference your npm package (I assume it's not hosted at npmjs.com) you can specify a git repository or local path. Here is an example of package.json

{
  "name": "foo",
  "version": "0.0.0",
  "dependencies": {
    "my_git_package": "git+ssh://user@hostname/project.git#commit-ish",
    "my_local_package": "file:../foo/bar"
  }
}

Take a look at dependencies section here https://docs.npmjs.com/files/package.json