简体   繁体   English

将使用angular-cli创建的Angular4(Angular)部署到Google App Engine

[英]Deploy Angular4 (Angular) created using angular-cli to Google App Engine

I have created a Angular4 or simply "Angular" application using Angular-CLI. 我已经使用Angular-CLI创建了Angular4或只是“ Angular”应用程序。 Now i could run it locally using "ng serve" and it works fine. 现在,我可以使用“ ng serve”在本地运行它,并且效果很好。 Now i want to deploy it to Google App Engine, ng build --prod builds all files to dist folder. 现在,我要将其部署到Google App Engine中,ng build --prod会将所有文件构建到dist文件夹。

Now how should i deploy them to google app engine? 现在我应该如何将它们部署到Google App Engine?

EDIT: 编辑:

I forgot to mention this, i want to deploy using maven. 我忘了提及这一点,我想使用Maven进行部署。 is there any dependency i can add to pom.xml. 有什么可以添加到pom.xml的依赖项吗? so that i can do everything from mvn? 这样我就可以从mvn做所有事情?

you can use maven in this way as a wrapper to create the build and to create a zip to upload. 您可以通过这种方式将maven用作包装,以创建构建并创建要上传的zip。 This is an implementation using yarn and npm. 这是使用yarn和npm的实现。

${project.artifactId} $ {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>

I created a App Engine yaml for serving Angular 4 dist folder. 我创建了一个App Engine Yaml,用于提供Angular 4 dist文件夹。 Looking for any feedback on how to improve it. 寻找有关如何改进它的任何反馈。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM