How to run the Dist Folder on Local Machine in Angular 6+?

前端 未结 6 1409
无人共我
无人共我 2020-12-07 16:47

I am building the application in Angular6+, now I have run the command ng build --prod which gave me a dist folder. Now how to check or serve that

相关标签:
6条回答
  • 2020-12-07 17:05

    You can do that using http-server package.

    First install the package globally

    npm install http-server -g

    Then inside your project directory(in the terminal) just run

    http-server dist/

    And if you are using Angular 6+ or above (Working with Angular 10), You have to run

    http-server dist/your-project-name

    Now you can visit http://localhost:8080 to view your application

    0 讨论(0)
  • 2020-12-07 17:05

    In my case I did next:

    Install http-server globally

    npm install http-server -g

    Then inside the project directory (in the terminal), I run

    http-server dist/[your-project-name]

    Now you can visit http://localhost:8080/index.html to view your application. But when I restart the browser page I have to add again /index.html into URL.


    It works in Angular 7.x.x version.

    0 讨论(0)
  • 2020-12-07 17:11

    Since Angular 7 you can just do ng serve --prod=true. Documentation: https://angular.io/cli/serve

    I know the question asks about Angular 6 but Google got me here, so just for future reference.

    0 讨论(0)
  • 2020-12-07 17:15

    Thanks mike "ng serve --prod=true" works perfect!!!!

    0 讨论(0)
  • 2020-12-07 17:17

    windows platform

     - Install wamp server --> 
       https://wampserver.en.softonic.com/ and start.
     - your dist folder files copy to c:/wamp/www/(your project name)/
     - And create .htaccess file redirect your index.html.
       (http://www.htaccesstools.com/htaccess-faq/)
     - Next run browser http://localhost/(your project name)
    

    ubuntu platform

     - Install lamp server --> 
       https://www.linode.com/docs/web-servers/lamp/install-lamp-stack-on-ubuntu-16-04/ and start.
     - your dist folder files copy to /opt/lampp/htdocs/(your project name)/
     - And create .htaccess file redirect your index.html.
       (http://www.htaccesstools.com/htaccess-faq/)
     - Next run browser http://localhost/(your project name)
    
    0 讨论(0)
  • 2020-12-07 17:22

    From Terminal:
    $ npm install http-server -g

    From Angular Project Dir. Lets say your Angular project name is ngx.
    $ ng build
    $ http-server dist/ngx
    Starting up http-server, serving dist/ngx
    Available on:
    http://127.0.0.1:8080
    http://192.168.43.54:8080
    Hit CTRL-C to stop the server

    Enjoy!

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