vue-cli icon indicating copy to clipboard operation
vue-cli copied to clipboard

vue-cli-service-build-target-lib-loses-images-path-when-imported-as-lib

Open johnsky123 opened this issue 7 years ago • 3 comments

Version

3.5.0

Reproduction link

https://stackoverflow.com/questions/51523450/vue-cli-service-build-target-lib-loses-images-path-when-imported-as-lib

Environment info

mac os

Steps to reproduce

There is no solution to this problem

What is expected?

solve this problem

What is actually happening?

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 the svg image is bundled under dist/img/hue-circle123456.svg.

Now when installing the module with npm install --save 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 command.

Thanks for the help!

johnsky123 avatar Jun 04 '19 09:06 johnsky123

This is not a reproduction link, it's a link to SO, where we find a link to a github repository, but that reporistory does not demonstrate the problem - it's the lib's source, which seems to have the problem when used in another project. You try to describe what you did but it's not really clear what the exact problem is, what the errors are that you receive etc.

Please help us help you and provide a clear reproduction that we can clone and run.


That being said, as far as I can tell from your description, this is a typical problem with assets from npm packages, and not directly related to Vue CLI.

When you import bundled javascript code from an npm package (e.g. your library) into a main app, and that code contains hardcoded HTML asset paths (like your library does, with that svg src link), then you will have to manually copy the assets from the npm package to e.g. your main project's /public folder, or e.g. use a webpack copy plugin to copy over those assets to /dist on build.

This is because webpack can't know which assets form which npm package to move where within the context of the main application that you installed the library in, so I don't think there's much we can do.

If you imported the package's source from instead of the bundled code, webpack could process the source assets and create them in /dist itself.

LinusBorg avatar Jun 04 '19 11:06 LinusBorg

Hello! This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues requiring feedback after 20 days of inactivity. It’s been at least 10 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. (A maintainer can also add the label not stale to keep this issue open.)

Thanks for being a part of the Vue community! 💪💚️

vue-bot avatar Jun 29 '19 09:06 vue-bot

Hey again! 😸️

It’s been 20 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. 🤖 Please feel free to reopen this issue or create a new one if you need anything else.

Thanks again for being part of the Vue community! 💚️

vue-bot avatar Jul 09 '19 09:07 vue-bot