【问题标题】:Deploy Angular4 (Angular) created using angular-cli to Google App Engine将使用 angular-cli 创建的 Angular4 (Angular) 部署到 Google App Engine
【发布时间】:2017-03-27 09:02:40
【问题描述】:

我使用 Angular-CLI 创建了一个 Angular4 或简单的“Angular”应用程序。现在我可以使用“ng serve”在本地运行它,它工作正常。现在我想将它部署到 Google App Engine,ng build --prod 将所有文件构建到 dist 文件夹。

现在我应该如何将它们部署到谷歌应用引擎?

编辑:

我忘了提这个,我想使用 maven 进行部署。有没有我可以添加到 pom.xml 的依赖项。这样我就可以从 mvn 做所有事情了?

【问题讨论】:

标签: maven angular google-app-engine visual-studio-code angular4


【解决方案1】:

您可以通过这种方式使用 maven 作为包装器来创建构建并创建要上传的 zip。这是一个使用纱线的实现 和 npm。

${project.artifactId}

<plugins>

  <!-- ############################## -->
  <!-- npm scripts                    -->
  <!-- ############################## -->

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <executions>
      <execution>
        <id>exec-yarn-install</id>
        <phase>generate-sources</phase>
        <configuration>
          <executable>npm</executable>
          <arguments>
            <argument>install</argument>
            <argument>--global</argument>
            <argument>yarn</argument>
          </arguments>
        </configuration>
        <goals>
          <goal>exec</goal>
        </goals>
      </execution>
      <execution>
        <id>exec-project-dependencies-install</id>
        <phase>generate-sources</phase>
        <configuration>
          <executable>yarn</executable>
        </configuration>
        <goals>
          <goal>exec</goal>
        </goals>
      </execution>

      <!-- run `ng build -prod -aot` -->
      <!-- * clean dist/ before generating distribution files -->
      <execution>
        <id>exec-compile</id>
        <phase>generate-sources</phase>
        <configuration>
          <executable>yarn</executable>
          <arguments>
            <argument>run</argument>
            <argument>build</argument>
          </arguments>
        </configuration>
        <goals>
          <goal>exec</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

  <!-- generate zip -->
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.3</version>
    <configuration>
      <descriptors>
        <descriptor>src/assembly/static.xml</descriptor>
      </descriptors>
    </configuration>
    <executions>
      <execution>
        <id>make-assembly</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>

【讨论】:

    【解决方案2】:

    我创建了一个 App Engine yaml 来为 Angular 4 dist 文件夹提供服务。寻找有关如何改进它的任何反馈。

    service: stage
    runtime: python27
    api_version: 1
    threadsafe: true
    
    skip_files:
    - ^(?!dist)  # Skip any files not in the dist folder
    
    handlers:
    # Routing for bundles to serve directly
    - url: /((?:inline|main|polyfills|styles|vendor)\.[a-z0-9]+\.bundle\.js)
      secure: always
      redirect_http_response_code: 301
      static_files: dist/\1
      upload: dist/.*
    
    # Routing for a prod styles.bundle.css to serve directly
    - url: /(styles\.[a-z0-9]+\.bundle\.css)
      secure: always
      redirect_http_response_code: 301
      static_files: dist/\1
      upload: dist/.*
    
    # Routing for typedoc, assets and favicon.ico to serve directly
    - url: /((?:assets|docs)/.*|favicon\.ico)
      secure: always
      redirect_http_response_code: 301
      static_files: dist/\1
      upload: dist/.*
    
    # Any other requests are routed to index.html for angular to handle so we don't need hash URLs
    - url: /.*
      secure: always
      redirect_http_response_code: 301
      static_files: dist/index.html
      upload: dist/index\.html
      http_headers:
        Strict-Transport-Security: max-age=31536000; includeSubDomains
        X-Frame-Options: DENY
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-12-10
      • 1970-01-01
      • 2017-02-08
      • 2018-05-29
      • 2021-03-01
      • 1970-01-01
      • 2018-01-03
      相关资源
      最近更新 更多