Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng serve removes /dist directory, but I would like to have it under version control #4366

Closed
stepanzarubin opened this issue Feb 2, 2017 · 37 comments

Comments

@stepanzarubin
Copy link

stepanzarubin commented Feb 2, 2017

angular-cli@1.0.0-beta.28.3

@grizzm0
Copy link
Contributor

grizzm0 commented Feb 2, 2017

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.

@stepanzarubin
Copy link
Author

@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.

@stepanzarubin
Copy link
Author

stepanzarubin commented Feb 3, 2017

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.

@grizzm0
Copy link
Contributor

grizzm0 commented Feb 3, 2017

It was changed as alot of people thought ng serve would serve the dist folder if present.

@filipesilva You got any input on this?

@stepanzarubin
Copy link
Author

@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:

  1. I make build: ng build --env prod which will write it under dist folder
  2. Then I run ng serve and my build is gone... wow

Why do I stop ng serve at all to make a build?

@grizzm0
Copy link
Contributor

grizzm0 commented Feb 3, 2017

Build is part of my deploy flow. I guess that's how most people use it.

@stepanzarubin
Copy link
Author

@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).

@stepanzarubin
Copy link
Author

I believe each command should remove/update only files this command is working with. ng build can clean build directory, but not other command.

@grizzm0
Copy link
Contributor

grizzm0 commented Feb 3, 2017

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.

@stepanzarubin
Copy link
Author

The world is not perfect, tests does not cover everything perfectly, some people do not write tests.

@grizzm0
Copy link
Contributor

grizzm0 commented Feb 3, 2017

You could still rollback by tag or keep releases on your prod server. :p

@filipesilva
Copy link
Contributor

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/

@mzeromski
Copy link

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.

@lgellert
Copy link

lgellert commented Apr 12, 2017

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.

@pljspahn
Copy link

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?

@jakeNiemiec
Copy link

jakeNiemiec commented Apr 19, 2017

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.

@JasonGoemaat
Copy link

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...

@filipesilva
Copy link
Contributor

filipesilva commented May 18, 2017

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.

@d42ohpaz
Copy link

d42ohpaz commented May 22, 2017

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!

@filipesilva
Copy link
Contributor

@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 (#1692), but you can find some temporary guidance in #1692 (comment) and #1692 (comment).

@severin2
Copy link

I realize that this is closed, but I keep ending up on this issue while searching for a while to make ng-cli clean everything inside of dist/ but not remove the folder. There's a definite use case for it.

In our case we are building the app with the angular cli and serving it with the nginx docker container. During development, we simply volume map the dist directory of our project to that container so we can see updates without starting the container.

Docker volume mapping strongly disagrees with removing the root volume mapped directory. And yeah we could map the next directory up and use docker trickery to ignore large folders like node_modules.

As another point of interest, we have a separate project where we added webpack manually to an old app, and we had to explicitly tell it to clean dist/* insead of dist/ to solve this problem.

@filipesilva
Copy link
Contributor

@severin2 the --delete-output-path=false option was added for that specific scenario. See https://github.com/angular/angular-cli/wiki/build for details.

@JohnYoungers
Copy link

I believe ng serve --delete-output-path false is working for me.

One thing to note that while the flag is documented in the wiki for the build command, it's not documented for serve.

In my situation, once deployed the UI and API run under the same webserver. As part of the build I have a test to verify static content is being served with a no-cache header. That works fine on the build server, but locally I wasn't able to run the test since the dist folder was being removed on ng serve (npm postinstall will stub in a fake file specifically for this test; during the actual build that folder gets replaced)

@izy2nv
Copy link

izy2nv commented Nov 13, 2017

@filipesilva I'm trying to integrate my angular 4 project in an already existing maven project. I understand the '/dist' folder has to be referenced in the 'target' dir of my maven project. How can this integration be done in this case since angular-cli deletes my dist folder?

@bastienJS
Copy link

@izy2nv Try ng serve --deleteOutputPath=false that worked for me prevention the deletion of my outDir value.

@figloalds
Copy link

figloalds commented Jan 9, 2018

I too got annoyed by that angular/cli screwover, but to me making a custom npm run build was even more convenient since I can use npm run build --prefix from parent folder (which holds many more projects and the actual dist folder), makes my workflow a bit more fluid.

@d42ohpaz
Copy link

d42ohpaz commented Jan 9, 2018

@felyperennan open a new ticket. this one is closed, and as such, it seems the devs stop caring about it.

@figloalds
Copy link

figloalds commented Jan 11, 2018

I'm not asking this to be changed, I think everyone already adapted to this by this point, I'm just adding how a custom npm script can be even more beneficial than having this particular behavior changed. But thanks anyways.

@johnking
Copy link

johnking commented Feb 2, 2018

Just want to add my two cents here.

I am developing a desktop app with electron, so I need to keep the dist folder to make electron running, in the meantime, I can run ng server for angular component development.

ng serve --deleteOutputPath=false is good enough for my case.

thanks

@shoagraw
Copy link

it deleted some on my work in progress file and not able to find those files now, not even in recycle bin,
Any idea where these files will go after ng build deletes these.

@jakeNiemiec
Copy link

@shoagraw, they are deleted permanently from the filesystem: https://github.com/angular/angular-cli/blob/master/tools/publish/src/build.ts#L75

@hamdimefteh
Copy link

change /dist to other folder path !

@EliezerB123
Copy link

Running "ng build --output-path='../'" , instead of creating a directory in the parent named "dist", just deleted 12 hours of my work.

A little warning, or maybe an error message would have been nice.

Instead, AFTER my entire project was deleted, I got a cheery little message saying "Path must be a string. Received null"

dond2clouds pushed a commit to d2clouds/speedray-cli that referenced this issue Apr 23, 2018
@michaelb-01
Copy link

Has the delete-output-path flag been removed in Angular CLI 6.0.0?

@rsheptolut
Copy link

It also seems Angular CLI 6.0.0 stopped deleting the "dist" folder by default. Had to add rmdir .\\dist /S /Q && to my npm start script before ng serve, because oddly enough I've depended on the old behavior 🙂

ninrod added a commit to ninrod/kotlin-springboot2 that referenced this issue Jan 4, 2019
gkalpak added a commit to gkalpak/angular that referenced this issue Jun 7, 2019
Previously, we run the PWA score tests before unit/e2e tests, because
the latter would destroy the `dist/` directory required by the former.

Since cli@6, unit/e2e tests no longer detroy the `dist/` directory, so
it is now safe to run the unit/e2e tests first. This is preferrable,
since they are conceptually lower-level and any error messages (in case
of breakage) are more specific/actionable.

Related discussion about cli behavior: angular/angular-cli#4366
gkalpak added a commit to gkalpak/angular that referenced this issue Jun 13, 2019
Previously, we run the PWA score tests before unit/e2e tests, because
the latter would destroy the `dist/` directory required by the former.

Since cli@6, unit/e2e tests no longer detroy the `dist/` directory, so
it is now safe to run the unit/e2e tests first. This is preferrable,
since they are conceptually lower-level and any error messages (in case
of breakage) are more specific/actionable.

Related discussion about cli behavior:
- angular/angular-cli#4366
- angular/angular-cli#14701
gkalpak added a commit to gkalpak/angular that referenced this issue Jun 14, 2019
Previously, we run the PWA score tests before unit/e2e tests, because
the latter would destroy the `dist/` directory required by the former.

Since cli@6, unit/e2e tests no longer detroy the `dist/` directory, so
it is now safe to run the unit/e2e tests first. This is preferrable,
since they are conceptually lower-level and any error messages (in case
of breakage) are more specific/actionable.

Related discussion about cli behavior:
- angular/angular-cli#4366
- angular/angular-cli#14701
gkalpak added a commit to gkalpak/angular that referenced this issue Jun 14, 2019
Previously, we run the PWA score tests before unit/e2e tests, because
the latter would destroy the `dist/` directory required by the former.

Since cli@6, unit/e2e tests no longer detroy the `dist/` directory, so
it is now safe to run the unit/e2e tests first. This is preferrable,
since they are conceptually lower-level and any error messages (in case
of breakage) are more specific/actionable.

Related discussion about cli behavior:
- angular/angular-cli#4366
- angular/angular-cli#14701
gkalpak added a commit to gkalpak/angular that referenced this issue Jun 14, 2019
Previously, we run the PWA score tests before unit/e2e tests, because
the latter would destroy the `dist/` directory required by the former.

Since cli@6, unit/e2e tests no longer detroy the `dist/` directory, so
it is now safe to run the unit/e2e tests first. This is preferrable,
since they are conceptually lower-level and any error messages (in case
of breakage) are more specific/actionable.

Related discussion about cli behavior:
- angular/angular-cli#4366
- angular/angular-cli#14701
AndrewKushnir pushed a commit to angular/angular that referenced this issue Jun 14, 2019
Previously, we run the PWA score tests before unit/e2e tests, because
the latter would destroy the `dist/` directory required by the former.

Since cli@6, unit/e2e tests no longer detroy the `dist/` directory, so
it is now safe to run the unit/e2e tests first. This is preferrable,
since they are conceptually lower-level and any error messages (in case
of breakage) are more specific/actionable.

Related discussion about cli behavior:
- angular/angular-cli#4366
- angular/angular-cli#14701

PR Close #31047
AndrewKushnir pushed a commit to angular/angular that referenced this issue Jun 14, 2019
Previously, we run the PWA score tests before unit/e2e tests, because
the latter would destroy the `dist/` directory required by the former.

Since cli@6, unit/e2e tests no longer detroy the `dist/` directory, so
it is now safe to run the unit/e2e tests first. This is preferrable,
since they are conceptually lower-level and any error messages (in case
of breakage) are more specific/actionable.

Related discussion about cli behavior:
- angular/angular-cli#4366
- angular/angular-cli#14701

PR Close #31047
@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests