Prevent vue cli from deleting all files in dist

Viewed 5201

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?

2 Answers

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

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

Related