ng serve removes /dist directory, but I would like to have it under version control
This was done on purpose in #4293. Any reason why you would want dist in VCS?
Without a build before committing the build would be out of sync with the current revision anyhow.
@grizzm0 because dist is synonym of an actual build, and it is, ng serve serves the actual code base, but not the build, build is done once per week, month, etc. and has nothing to do with a current working directory. Another synonym of a dist is release, a lot of packages/libraries put their releases under dist directory and have it under version control.
Also, having dist under VCS allows us to keep everything in one place.
ng serve should accomplish its own task => serve actual code. And suddenly it starts to remove files from the outside? this is weird, the other developer was confused, to get rid of a confusion it is enough to understand that there is nothing under dist directory when ng serve is running, README can be updated to clarify this.
At least, removing dist should not be a default behavior, can be achieved by specific configuration option or a command argument.
Thanks.
It was changed as alot of people thought ng serve would serve the dist folder if present.
@filipesilva You got any input on this?
@grizzm0 then, why to have a dist folder at all? what is a purpose of it? temporary folder for temporary content? let`s take a look at scenario:
- I make build:
ng build --env prodwhich will write it underdistfolder - Then I run
ng serveand my build is gone... wow
Why do I stop ng serve at all to make a build?
Build is part of my deploy flow. I guess that's how most people use it.
@grizzm0 what will happen if build was not successful? for any reason, build can output files successfully, but they may not work (e.g. local build is ok, but there is something wrong with prod one).
I believe each command should remove/update only files this command is working with. ng build can clean build directory, but not other command.
If tests fail during deploy the deploy will be cancelled. If it builds successfully but something is wrong I would either store x releases on the prod machine or rollback by checking out a previous tag and build from that.
The world is not perfect, tests does not cover everything perfectly, some people do not write tests.
You could still rollback by tag or keep releases on your prod server. :p
I'm sorry this change disrupted your workflow. We're not looking at changing it back though.
dist/ had, at best your last ng build and was never reflective of ng serve.
My recommendation for your particular case is to do make a build using the --output-path (-op) flag and keep that one under version control.
ng build --output-path=last-build/
My solution for this:
After update Jan 2017 noticed new problem. Command ng serve remove /dist dir.
Solution:
File: package.json (new command prod-build)
"scripts": { "ng": "ng", "start": "ng serve", "build": "ng build", "prod-build": "ng build --output-path=last-build/ --env=prod", "test": "ng test", "lint": "ng lint", "e2e": "ng e2e" }, File: angular-cli.json (change ourDir)
"outDir": "/tmp/dist",
To build your prod version run: npm run prod-build
To serve: ng serve
In this configuration: ng server will create tmp dir, and your project directory will be clean, even when you commit changes without stop ng serve.
Having the latest production build in /dist was part of my build process too. By setting up a command in package.json as @hinol suggested that sends it to a custom folder (/dist-prod/), I can live with it, minimal changes elsewhere.
My command is:
"build-prod": "ng build --prod --env=prod --output-path=dist-prod/" note the extra --prod flag, which does the uglifying and tree shaking.
Here because even when I'm building to another output path, that path gets wiped each time I build and I lose the .git folder.
Why can't it just spit the output to that folder instead of removing everything and then dumping the contents there?
Build is part of my deploy flow. I guess that's how most people use it.
@grizzm0 I have seen the light. Turns out I wasn't giving this a fair chance. Having TravisCI build & publish my npm package is so much better than commiting /dist to VCS.
This is SOOO wrong. 'ng serve' is deleting an entire directory's contents that might not even be your build output if you've changed its location. There is no documentation on this, deleting an entire directory seems to be a 'hidden feature' of the 'ng serve' command. In my experience having programs delete a directory without informing the user is a bad idea. At the very least there should be an output line when running 'ng serve' that says Deleting the contents of the dist directory...
I should mention that on 1.1.0-rc.0 there is a new --delete-output-path flag, defaulting to true. We introduced it both for Docker setups that link the dist directory, and for custom setups that use another build system to produce artifacts in dist.
Hello. @filipesilva and/or @grizzm0, I'm a bit new to the front-end development and using Angular's cli. I've never done deployments before, so I'm curious why having a dist/ folder that's not empty is somehow a bad thing?
Also, isn't the suggestion of renaming the dist/ folder (i.e., last-build/) nothing more than lipstick on the proverbial pig? In other words, whatever the problem is with having a dist/ folder won't actually be solved, because you've simply renamed it.
The reason why it confuses me is because I was reading an article about creating angular modules for NPM, and it's rule of thumb is to build into the dist directory, and push to npm from there, so that only the necessary files get published. If this is not the correct workflow, would you have any documentation about the best-practice workflow developers should be using?
Thank you in advance!
@dohpaz42 while a dist/ folder contains build artifacts for both apps and libraries, they are used differently. For apps, the dist folder is often deployed, while for libraries it can be installed via the dependency manager or linked for live development.
There is no problem in having a non-empty dist/ per se, but due to it being a auto-generated folder in both cases, it's content is transient during development cycles. The build system deletes and recreates it's contents as needed.
Take for instance fingerprinting - the hash that gets appended during production builds. If dist/ wasn't deleted wholesale between builds, it would quickly accumulate a lot of past artifacts that are not used anymore. This also happens for any files in assets that you had at one point and removed since.
There are some advanced usecases where it is desirable to not delete the dist/ folder, such as symlinks for docker development or when multiple build systems are outputting to dist/, but those are the exceptions rather than the norm.
Angular CLI does not yet support libraries (https://github.com/angular/angular-cli/issues/1692), but you can find some temporary guidance in https://github.com/angular/angular-cli/issues/1692#issuecomment-285363067 and https://github.com/angular/angular-cli/issues/1692#issuecomment-301736484.