Prevent vue cli from deleting all files in dist
Asked Answered
W

2

5

I am developing vue project and syncing dist folder with git. This worked well while using webpack. However, I have moved to @vue/cli --- using vue create myProject instead of vue init webpack myProj.

The issue is that every time i run npm run build, it deletes dist folder and recreates it -- all .git and other files gone.

How do I prevent new build from deleting required files in dist folder and only update the changes?

Williwaw answered 26/5, 2020 at 13:37 Comment(0)
W
1

Thanks to answer by Yom S. the documentation here does provide way to keep older dist.

However, the you can't use --no-clean like npm build --no-clean. To use no clean mode from terminal you need to write following command instead

./node_modules/.bin/vue-cli-service --no-clean

Update

Instead you can also add --no-clean in package.json

Williwaw answered 26/5, 2020 at 15:11 Comment(1)
Actually I think you can do that. You just need to pass the parameter a little differently, given npm script build: vue-cli-service build you can pass additional flags after -- so in CLI you'd call npm run build -- --no-clean and npm would pass the params after -- to the actual script command.Coreencorel
C
10

Assuming you have your own mechanism for cleaning up the old resources, vue-cli-service build comes with this option called --no-clean to instruct the compiler not to remove the "dist" directory before building the project.

So, add the switch/option to the build script on package.json:

{
  "scripts": {
    "build": "vue-cli-service build --no-clean"
  }
}

Alternatively, if you use Yarn, you can pass additional argument(s) right after the script name. So there's no need to make any change to the script. To run it:

yarn build --no-clean
Confute answered 26/5, 2020 at 13:55 Comment(3)
tried npm run build --no-clean --- old files removed (created test.txt in dist folder to test)Williwaw
It won't work like this. You have to provide --no-clean to vue-cli-service so best way is to put this to package.json as "build": "vue-cli-service build --no-clean", and then you can just run npm run build @mayank1513Nels
Thanks for clarifying that, @KoviNET. I updated the answer to include that.Confute
W
1

Thanks to answer by Yom S. the documentation here does provide way to keep older dist.

However, the you can't use --no-clean like npm build --no-clean. To use no clean mode from terminal you need to write following command instead

./node_modules/.bin/vue-cli-service --no-clean

Update

Instead you can also add --no-clean in package.json

Williwaw answered 26/5, 2020 at 15:11 Comment(1)
Actually I think you can do that. You just need to pass the parameter a little differently, given npm script build: vue-cli-service build you can pass additional flags after -- so in CLI you'd call npm run build -- --no-clean and npm would pass the params after -- to the actual script command.Coreencorel

© 2022 - 2024 — McMap. All rights reserved.