多个 Angular2 应用程序,单一供应商存储库

Multiple Angular2 Applications, Single Vendor Repository

我想托管各种 Angular2 应用程序,这些应用程序使用相同的框架包和 node_modules 来自根域和子域:

  1. domain.com
  2. subdomain.domain.com
  3. sub2.domain.com

文件夹结构

public_html 
├── SUBDOMAINS
│   ├── sub2
│   │   ├── assets
│   │   └── src
│   └── subdomain
│       ├── assets
│       └── src
├── assets
├── boot.ts
├── index.html
├── node_modules
├── package.json
├── src
└── tsconfig.json

我希望能够利用 root 应用程序 的资源而不需要重复代码。

一种方法是使用 webpackgulp。您需要在 tsconfig.json 中使用 commonjs 作为模块。

  • 使用 webpack 将每个单独的项目 ts 文件打包为一个包。
  • 借助 gulp 任务,您可以将每个项目分组到不同的
    目标文件夹。
  • 为每个项目目标文件夹创建 index.html 文件并 将您的 js/ts 包作为脚本包含在其中。
  • 使用webpack dev server监听不同的端口 项目 index.html 文件。

    gulp.task("webpack-dev-serverWeb", function(callback) {
    var myConfig = Object.create(webpackConfig);
    new myWebpackDevServer(mywebpack(myConfig), {
        publicPath: "/" + myConfig.output.publicPath,
        stats: {
            colors: true
        }
    }).listen(8080, "localhost", function(err) {
        if (err) throw new gutil.PluginError("webpack-dev-server", err);
        gutil.log("[webpack-dev-server]", "http://localhost:8080/webpack-dev-server/your_path_to_index.html_for_port_8080/index.html");
    });