how to deploy angular2 app built using angular-cli

后端 未结 9 828
误落风尘
误落风尘 2021-01-30 07:05

I have created n new angular app using angular-cli.

I completed the app and preview it using ng-serve, it is working perfectly.

After that I used ng build --

相关标签:
9条回答
  • 2021-01-30 07:46

    http-server doesn't support client-side routing, so nothing other than your base URL is going to work. Instead, you can use angular-http-server:

    npm install -g angular-http-server
    ng build --prod
    cd dist
    angular-http-server
    

    This should only be used to test the app locally before deploying it on a Web server. To learn how to actually deploy the app on a Web server, check out the Angular.io article on deployment, which discusses considerations to make when building for deployment and provides configurations for a variety of different Web servers commonly used in production.

    0 讨论(0)
  • 2021-01-30 07:47

    Use ng build with the --bh flag

    Sets base tag href to /myUrl/ in your index.html:

    ng build --base-href /myUrl/
    ng build --bh /myUrl/
    
    0 讨论(0)
  • 2021-01-30 07:50

    I'm using the latest version of the Angular-CLI (at the time of this reply its 1.0.0Beta-18)

    The way this version works is it puts everything in bundle files and it calls them in the index.html file. After that you have to copy your assets over to the dist folder (for some reason it does not do that). Finally, double check your base href make sure its set to what it needs to be set to and then it should work. That's what worked for me and I've tested on both Apache and Node.

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