Angular-cli: Feature Request: Stop deleting 'dist' directory on 'ng serve' (SILENTLY)

Created on 18 May 2017  路  7Comments  路  Source: angular/angular-cli

Bug Report or Feature Request (mark with an x)

- [X] feature request

Versions.

@angular/cli: 1.0.0-rc.1
node: 6.10.2
os: win32 x64
@angular/common: 2.4.9
@angular/compiler: 2.4.9
@angular/core: 2.4.9
@angular/forms: 2.4.9
@angular/http: 2.4.9
@angular/platform-browser: 2.4.9
@angular/platform-browser-dynamic: 2.4.9
@angular/router: 3.4.9
@angular/cli: 1.0.0-rc.1
@angular/compiler-cli: 2.4.9

Repro steps.

run "ng build" then "ng serve"

Desired functionality.

'ng serve' silently deletes the hard-coded 'dist' directory and should not.

Mention any other details that might be useful.

'ng serve' currently deletes the dist directory contents despite having nothing to do with the 'dist' directory. AND IT DOES THIS SILENTLY. The user might build into a different directory and store important information in the dist directory, which they would lose when calling 'ng serve'. People might use the dist directory for a lot of things. They might WANT to check in their weekly builds, either into the same repository or as a submodule so it can be imported into another project to serve the files. They might have a standard at their company to store things in a dist directory and build into a different directory, then 'ng serve' would delete files it has zero rights to delete.

If this is just done because people mistakenly think that 'ng seve' is serving the contents of the 'dist' directory it is a user education item and should be handled by a message when running 'ng serve' explaining this, not by silently deleting files.

A command line parameter like ng serve --keep-dist would be ok. At the very least there should be a message when running ng serve telling the user that it is deleting the contents of a directory.

easy (hours) 3 (nice to have) inconvenient

Most helpful comment

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"

All 7 comments

For our workflow we serve the angular-cli app inside an ASP.NET Core web application. The 'dist' directory is a submodule of our angular-cli project and also of the ASP.NET Core web application (in the wwwroot directory). So when we have a new version of the angular code, we do a build, then commit the changes in the submodule (with a tagged version, etc). Then in our ASP.NET Core application we simply update the submodule.

We initially did this because angular-cli wouldn't build in Azure when pulling our project from source control. If that has changed we might go back to just including the angular project as a submodule directly, but still deploys would take an extra couple minutes to build the cli project.

I can tell that you put a lot of thought into writing this issue, but I'm sorry to have to tell you that it's still a dupe of https://github.com/angular/angular-cli/issues/4366, and what had to be said about this subject has been said there (you even commented there yourself).

If you're keeping important things in your dist/ dir, then you have to change outDir in your .angular-cli.json so that the CLI uses another folder for build artifacts it on build/serve commands. Starting in 1.1.0-rc.0 you also have the --delete-output-path flag, defaulting to true.

@filipesilva Ok, you laid down the law. Despite it not being the best option for some people you still want to delete a directory and have no option to avoid this.

At the very least you should inform the user when they run 'ng serve' that it is deleting a directory. I don't know how you can say it's a good practice to delete a directory without informing a user. A directory they know was created and populated when they ran 'ng build', or maybe a directory they put non-build related files in themselves when they changed the build output to go to another directory. I don't know how any user wouldn't be surprised when those contents were suddenly gone unless they are reading these issues.

The 'ng serve' command has nothing to do with the directory. The 'ng build' command is what populates that directory. Deleting the contents when 'ng serve' is run is a hack because some users mistakenly thought they were getting that directory's contents with 'ng serve', but it isn't well documented and it is counter-intuitive. I've never seen a command before in my life that deletes the contents of a directory that it doesn't normally concern itself with.

Since the 'functionality' of the 'ng serve' command won't be changed, I'll open separate tickets for the command line option and adding a message informing the user to make it easier.

The command line option ( --delete-output-path, which you can set to false) currently exists though, and I don't think a message every time ng build/serve/e2e run is very useful - it just becomes white noise after one or two times.

I do agree that it might be unexpected in some setups (like the one you described), but I think that in a lot of setups it's not surprising at all that the output directory for the build system is wholly transient and that there are a lot of commands to wipe/rebuild it.

You're quite right that this is poorly documented. I'll add a note to the build command docs.

@filipesilva what version did this go in to?

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"

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hartjo picture hartjo  路  3Comments

jmurphzyo picture jmurphzyo  路  3Comments

rajjejosefsson picture rajjejosefsson  路  3Comments

5amfung picture 5amfung  路  3Comments

IngvarKofoed picture IngvarKofoed  路  3Comments