Angular 2 CLI - How to use /dist folder files created by angular-cli ng build

前端 未结 4 835
野的像风
野的像风 2020-12-24 06:40

I\'m generating dist folder after ng build and my directory looks like

C:\\Source\\angular> ng build

cut and past the dist fold

相关标签:
4条回答
  • After ng build, it just needs a server to execute it, instead of ng serve you can install an http-server from your terminal npm i -g http-server --save then execute your project from the dist folder using the command (y) :

    http-server ./dist
    

    Or on apache for who are using Wamp or Xamp for example just copy the entire files on the dist folder inside your www folder, then restart Apache service

    0 讨论(0)
  • 2020-12-24 07:27

    Steps to create build is

    > ng build --prod // can be other environment
    

    To serve /dist folder created by angular-cli ng build command we can use "serve" use below command to install serve

    > yarn global add serve
    

    and run

    serve dist/
    

    You will get url and try it on any browser.

    0 讨论(0)
  • 2020-12-24 07:28

    If you deploy the angular4 project on you webserver to sub folder DOCUMENT_ROOT/test, then you can do the build as follows:

    ng build --prod --base-href "/test/".

    Copy the dist/* files to DOCUMENT_ROOT/test.

    Access the app through: http://myserver/test. That worked for me.

    0 讨论(0)
  • 2020-12-24 07:30

    Dist folder is not for ng serve

    It's a build that you can run without ng commands

    ng build :
    

    It creates the build of your project , converts all your ".ts files" and other files to the simple js files that browser can understand.

    So there is no need to run ng serve over the dist folder ,

    just open index.html file inside dist folder and your whole project will run.

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