angular / angular-cli

CLI tool for Angular
https://cli.angular.dev
MIT License
26.77k stars 11.98k forks source link

can ng serve build files in a physical directory? #3755

Closed keslavi closed 7 years ago

keslavi commented 7 years ago

Please provide us with the following information:

OS?

Windows 2008 server

Versions.

angular-cli: 1.0.0-beta.24 node: 6.9.1 os: win32 x64 @angular/common: 2.4.1 @angular/compiler: 2.4.1 @angular/core: 2.4.1 @angular/forms: 2.4.1 @angular/http: 2.4.1 @angular/platform-browser: 2.4.1 @angular/platform-browser-dynamic: 2.4.1 @angular/router: 3.4.1 @angular/compiler-cli: 2.4.1

Repro steps.

run ng serve

The log given by the failure.

not an error

Mention any other details that might be useful.


ng serve builds and serves the files in memory. Is it possible to make ng serve build and serve from a physical directory instead? /dist/dev, for example?

I'm constrained by my environment's authentication to run within IIS and therefore need a location I can attach a virtual directory to .

I realize I could concurrently do an ng build but that seems wasteful.

eight-molecules commented 7 years ago

First and foremost: Do not serve production using ng serve. This is a blanket warning because it's just not safe. You're trusting a generic, minimal configuration to secure your app.

IIS has a couple ways to serve these apps, and each has pros and cons. The method I prefer is to run a back end server (Hapi, Express) on a high number port, then use URL Rewrite to turn IIS into a reverse proxy. The back end then serves your dist folder just like any production Angular app. If you have a lot of services on various ports and need a lot of choice in your stack this might be a good, extendable option.

The other one is to literally serve the dist folder. Angular 2 is built into a static set of files and needs no real processing on the local server. Build it, set your IIS config and baseHref, and away you go! More Details

keslavi commented 7 years ago

{clarification: i'm not doing this in prod, it's on the local dev box for development purposes.}

Thank you, gelliott, I'm looking at your answer now.

my hope is to change a file, press save, and have the changes reflected in the IIS location, similar to using gulp watch to retrigger the build.

because of the authentication in this case (siteminder) I doubt URL rewrite will work; it's already being redirected in IIS to inject headers and cookies. Yes, it hurts my head too, but that's my constraint.

With Angular-seed i do literally serve the dist/dev folder. ng serve doesn't have an output directory though. Therefore I was hoping for a way to configure ng serve to build to a physical directory.

I can think of a hackish way, such as adding a gulp watch to build on file changes, but trying to work within the cli.

eight-molecules commented 7 years ago

ng build --watch will watch the build folder and automatically build on changes.

The production comment is a boilerplate warning I give out in case a less well versed sysadmin sees this. Some devs don't understand the implications of a running a dev server vs a hardened production server.

keslavi commented 7 years ago

{doh} thank you

filipesilva commented 7 years ago

Closing as @gelliott181 has answered it, cheers!

angular-automatic-lock-bot[bot] commented 5 years ago

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.