How can I deploy an Angular 2 application on tomcat server (Windows Server 2012)

后端 未结 5 1693
情话喂你
情话喂你 2020-12-28 08:57

I\'m new in AngularJS 2 framework and I\'m stuck!

I want to deploy an application (quickstart for example) on a Windows Server 2012. I have already installed Apache

相关标签:
5条回答
  • 2020-12-28 09:38

    If your are using angular-cli command to create angular 2 project.Then cli has given some commands to deploy your application into production. Use command like ng build --prod on your project directory and it will generate dist folder in your directory.

    Go to inside dist folder and change the base href like href="." in index.html. After that copy dist folder in your tomcat root directory and run the server.. you can see below screen shot our application running on tomcat server.

    0 讨论(0)
  • 2020-12-28 09:40

    You can change one place in the index.html: <base href="/">
    Make the base href to be your relative path form webapps folder in tomcat to the folder that includes the index.html of your angular app.

    In your case, change it to: <base href="./dist">
    No other changes are needed.

    0 讨论(0)
  • 2020-12-28 09:45

    Just build it out using any of the build tasks(dev will include some source maps, and don't worry about having node on the server as node is only needed for the development tooling. Then just copy over all the files in the dist folder. Have a look in the index.html and make sure that the references to the various scrips are correct. The only thing the app needs to run is the scrips in the index, no node is needed.

    0 讨论(0)
  • 2020-12-28 09:48
    1. Run this command ng build --prod on your terminal
    2. After check one folder is created in parallel of src dist and go to dist folder and go to inside of your project folder and select all files and paste in inside of WebContant and parallel in web-INF and go to inside on index.html page and replace / from . in like href="." and go to url example: http://localhost:8080/ProjectName/#/URL and check it.
    0 讨论(0)
  • 2020-12-28 09:52

    I've found the solution:

    I had to insert the right path to the bundle files!

    I changed for example the src attribut of the index file from : src="inline.bundle.js"

    to : src="dist/inline.bundle.js"

    Just added the DIST FOLDEEEEEER ! Haha Thank you run yards for your help !

    0 讨论(0)
提交回复
热议问题