How to deploy Angular 2 application developed in Typescript to production?

前端 未结 6 725
情深已故
情深已故 2020-12-05 01:47

I am new to Angular 2. I am confused with how Angular 2 works in production environment.

  1. What are the prerequisites for running Angular 2 application in pr

6条回答
  •  孤城傲影
    2020-12-05 02:28

    1. An application server (for my answer, I used Tomcat), node.js, and angular-cli (by running "npm install -g angular-cli")
    2. You can deploy to other servers
    3. Just .html, .js and .map files (at least for my solution)

    This works better if you had created the application using angular-cli instructions shown here. In your application root directory, run the following command ng build --env=prod and that will bundle, via webpack, the deployable items in the \dist directory.

    Copy the \dist directory and paste it into {CATALINA_HOME}\webapps. Rename \dist to a folder name such as \foo. Open \foo\index.html and edit the base-href line to represent your new directory name:

    
    

    Start Tomcat via startup.bat or your chosen preference and navigate to http://localhost:8080/foo/ and you should be able to view your Angular 2 application.

    Note: If you had not created the project with ng new command, I had read where executing ng init before build will allow you to still follow the steps. I have not tested this myself though.

提交回复
热议问题