如何在不使用CLI的情况下部署Angular2项目

hem*_*123 9 angular

这是我为角度2制作的项目所做的文件夹结构.我删除了Node-Module文件夹和其他文件夹,以便在此处使用.对于造型我只使用了Bootstrap.我没有使用过Angular-CLI.任何人都可以指导我如何部署它?我应该使用gulp吗?我的步骤应该是什么.我在stackoverflow上经历了很多答案,但都使用了GULP和CLI.是否必须同时使用两者,如果是这样,请指导如何实现部署.遗憾的是,在Anular2官方网站上没有提到有关部署的内容.欢迎任何帮助,指导和建议.

|--app
|   |-- logo.png
|   |-- components
|   |   |-- main.component.ts
|   |   |-- config.component.ts
|   |   |-- download-resources.component.ts
|   |   |-- header-footer.component.ts
|   |   |-- licence.component.ts
|   |   |-- menu-bar.component.ts
|   |   |-- process-status.component.ts
|   |   |-- release-history.component.ts
|   |   |-- upload-release.component.ts
|   |   `-- version.component.ts
|   |-- main
|   |   `--module.ts
|   |-- main.ts
|   |-- models
|   |   |-- config.model.ts
|   |   |-- meta-info.model.ts
|   |   |-- process-status.model.ts
|   |   `-- version.model.ts
|   |-- services
|   |   |-- cc-info.service.ts
|   |   |-- config.service.ts
|   |   |-- release-history.service.ts
|   |   |-- shared.service.ts
|   |   |-- upload-release.service.ts
|   |   `-- version.service.ts
|   `-- template
|       |-- download-resources.component.html
|       |-- licence.component.html
|       |-- license-info.component.html
|       |-- machines.component.html
|       |-- menu-bar.component.html
|       |-- process-status.component.html
|       |-- release-history.component.html
|       |-- topology-info.component.html
|       |-- topology-upload.template.html
|       |-- upload-release.component.html
|       `-- version.component.html
|-- index.html
|-- package.json
|-- styles.css
|-- systemjs.config.js
|-- tsconfig.json
`-- typings.json
Run Code Online (Sandbox Code Playgroud)

这是我的system.config.js文件:

(function (global) {
  System.config({
    // DEMO ONLY! REAL CODE SHOULD NOT TRANSPILE IN THE BROWSER
    transpiler: 'ts',
    typescriptOptions: {
      tsconfig: true
    },
    meta: {
      'typescript': {
        "exports": "ts"
      }
    },
    paths: {
      // paths serve as alias
      'npm:': 'node_module'
    },
    // map tells the System loader where to look for things
    map: {
      // our app is within the app folder
      app: 'main-app',

      // angular bundles
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      '@angular/common': 'npm:@angular/common/bundles/common.umd.js',
      '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
      '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
      '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
      '@angular/http': 'npm:@angular/http/bundles/http.umd.js',
      '@angular/router': 'npm:@angular/router/bundles/router.umd.js',
      '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
      '@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',

      // other libraries
      'ng2-file-upload' : 'npm:ng2-file-upload',
      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api',
      'ts':                        'npm:plugin-typescript@4.0.10/lib/plugin.js',
      'typescript':                'npm:typescript@2.0.2/lib/typescript.js',

    },
    // packages tells the System loader how to load when no filename and/or no extension
    packages: {
      app: {
        main: './main.ts',
        defaultExtension: 'ts'
      },
      rxjs: {
        defaultExtension: 'js'
      },
      'angular-in-memory-web-api': {
        main: './index.js',
        defaultExtension: 'js'
      },
      'ng2-file-upload':{
        main: 'ng2-file-upload.js',
        defaultExtension: 'js'
      }
    }
  });
})(this);
Run Code Online (Sandbox Code Playgroud)

hem*_*123 3

我通过使用webpack解决了这个问题。我的 webpack 制作了一个bundle.js,其中包含所有 .js .ts .html 文件并将其转换为bundle.js。我在 Index.html 中导入。这个bundle.js包含它运行所需的所有东西。我的网站所需的其他内容(例如 style.css 和一些引导库)必须从外部包含在 index.html 中。您需要遵循的步骤是:

  1. 在 dev-dependency 的 package.json 中包含 "compression-webpack-plugin": "^0.3.2" 包
  2. 使用 webpack 时还有一些事情需要记住。您需要使用正确的语法将模板导入到 componenet 中,并且路由几乎没有变化。
  3. 我也在 package.json 中更改了构建脚本。添加了 webpack 工作的代码

    "build": "npm run tsc && npm run clean && mkdir _dist && webpack --devtool inline-source-map",

  4. 您需要配置您的 webpack。webpack.config.js 包含我所做的所有配置,它看起来像这样。

var webpack = require("webpack");
var CompressionPlugin = require("compression-webpack-plugin");  
module.exports = {
entry: {
 "app": "./app/main"
 },
        output: {
            path: __dirname,
            filename: "./_dist/bundle.js",
            publicPath: 'http://localhost:4242/app'
        },
 resolve: {
        extensions: ['', '.js', '.ts', '.html']
    },
    devtool: 'source-map',
    module: {
        loaders: [
            {
  test: /\.ts$/,
                loaders: ['awesome-typescript-loader', 'angular2-template-loader']
            },
            {
                test: /\.html$/,
                loader: 'html'
            }
    ]
},
htmlLoader: {
    minimize: false
},
plugins: [
    new webpack.NoErrorsPlugin(),
],
devServer: {
    historyApiFallback: true,
 stats: 'minimal',
        inline: true,
        port: 4242
    }
}
Run Code Online (Sandbox Code Playgroud)