I followed this guide to create my npm module. My repo contains in the src/assets folder an svg image (hue-cirle.svg).
When building with vue-cli-service build --target lib --name <lib-name>
the svg image is bundled under dist/img/hue-circle123456.svg
.
Now when installing the module with npm install --save <module>
the path remains src/img/hue-circle123456.svg
, while it should refer to the svg image from the node_modules dist folder and not to a non-existing hue-circle123456.svg
image from the main Vue App src folder.
Basically what happens is that the svg image path is wrong in the Vue project that uses my module. I tried to add the ~
to force webpack to interpret it as a module dependency as suggested here but it did not work.
In the end I gave up and embedded the svg in the html template as you can see in the repo. Nonetheless, I ask this question since I could not find any solution and I, as well as others, may need to solve this in order to use image resources in custom modules built with vue-cli-service build --target lib --name <lib-name>
command.
Thanks for the help!
alias
will fix this. When I check the bundle file after build as lib. I found my image waswebpack.__require__
and the path islocalhost:8080/xxx/my-image
But when I use the lib as a dependency in myproject1
, I saw the image request but there is no real image data responded with a success code 200 – Xiaojing Zhao