Changing the assets directory in Vue

Asked by At

I'm working on a project that was created using the vue cli 3.0. And on creation a src/assets folder is also made. This folder can include some images for example.

Is it possible to change the path of the assets to something different?

I tried changing the assetsDir setting in vue.config.js. But this only changes the output path in the build.

Edit:

I should note that I would like to load assets based on a "vendor" environment variable. So if I set this to vendorX it should load src/assets/vendorX and with vendorY it should load src/assets/vendorY.

Edit 2:

It appears that the directory name doesn't matter to the Vue Cli. I changed the assets folder name to vendors. But my guess is that Vue includes all resources files in src by default. So I'm now looking for a way to change this, or maybe find a different solution.

2 Answers

2
nicktu12 On

If the assets folder was setup with an alias, that would be found in webpack.config, however the vue-cli appears to create a project with hardcoded paths to the assets. Try changing the src path for your assets across all files to ./assetsDir/myImg.png.

1
Kelvin Omereshone On

You could check out this article by Anthony Gore on Medium. Might give you a hint. “Renaming src Folder of a Vue CLI 3 Project” by Anthony Gore https://link.medium.com/9fo6DbgxNV