As I attempt to publish a Vue library to npmjs, I encounter an issue with the images within it.
After publishing the app to NPM and importing it into my main app, everything appears to be working correctly. However, the paths to the images in the library are incorrect, and I am unable to fix them (I notice that the images are located in the node_modules folder of my library. Shouldn't my main vue app extract the images from the library when I run npm run serve
?)
To better understand this problem, I have created a simplified demo.
Within my Library, I have developed a basic component:
<div class="hello">
<h1>{{ msg }}</h1>
<img alt="Vue logo" src="@/assets/xlogo.png" />
<img alt="Vue logo" :src="require('../assets/xlogo.png')" />
<p>This is a paragraph.</p>
</div>
I then build the library using the following node command (the command is specified in the package.json, and I execute it via npm run build:lib
):
vue-cli-service build --target lib --name tmp ./src/components/index.vue
Subsequently, I import the library into my main vue app:
import HelloWorld from '../../tmp/dist/tmp.umd.js'
<template>
<HelloWorld msg="Welcome to Your Vue.js App.."/>
</template>
To illustrate this issue, I have set up a GitHub repository. How can I resolve this so that the images are included in the library? Any guidance would be greatly appreciated, as I have dedicated hours trying to solve this on my own already :(