问题描述
我有一个使用 AngularCli 在 Angular2 中开发的应用程序,我想将它用作另一个项目的布局"(如 MasterPage).就像一个巨大的SPA 系统".
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:
- 框架
- 页面 A
- 页面 B
框架在 http://localhost:90 中运行,XPTO 在 http://localhost:91.它们都在 AngularCli 上运行.
The Framework is running in http://localhost:90 and XPTO is running in http://localhost:91. Both of them is running on AngularCli.
我想创建一个结构,当我点击页面 A 或页面 B 时,浏览器不会重新加载,它会为用户提供应用程序"样式,将页面作为跨站点的 SPA 加载.
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.
主要原因是将来自Framework"项目的 Javascripts、CSS 和许多其他文件重用到其他 20 个项目中.我不想在这些项目中复制所有组件、文件等.
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.
今天我们使用 MVC3 和 RazorGenerator 创建 .cshtml 作为 DLL,以便将 .cshtml 从 Framework 重用于其他模块.
Today we use MVC3 and the RazorGenerator to create .cshtml as a DLL to reuse the .cshtml from Framework to other modules.
但我们想要使用 AngularCli.有没有办法做到这一点?如果不是,是否有某种方法可以在 AngularCli 中创建一个可以重用组件和其他文件的模板?
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 ?
谢谢!
推荐答案
您可以将共享的 Angular 组件和模块放入单独的 npm 包中,并将此包用作其他项目的依赖项.为了引用您的 npm 包(我假设它不在 npmjs.com 上托管),您可以指定一个 git 存储库或本地路径.这是 package.json 的一个例子
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" } }
在此处查看
dependencies
部分 https://docs.npmjs.com/files/package.json这篇关于如何创建一个包含另一个 AngularCli 的 AngularCli 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!