Having trouble processing images in multi-file components with Vue and TypeScript

Recently, I reorganized my component setup by implementing a multi-file structure:

src/components/ui/navbar/
    Navbar.component.ts
    navbar.html
    navbar.scss

Within the navbar.html file, there was an issue with a base64-encoded image <img />, which prompted me to externalize it into a separate multi-file component.

<div class="navbar-header">
    <router-link tag="a" to="/home" class="navbar-brand" href="#" title="CompanyName">
        <img class="img-fluid" src="./assets/logo.png" alt="CompanyName">
    </router-link>
</div>

Upon checking the dist/ folder, I realized that the logo.png file was missing. Furthermore, the final output no longer contained the base64 version of the image.

This led me to believe that there might be a configuration missing in the vue.config.js file to handle multi-file components (similar to Angular), but I couldn't find relevant information online.

Below is part of the current configuration I have, with certain sections commented out during testing:

module.exports = {
  chainWebpack: config => {
    if (process.env.NODE_ENV === "development") {
      config
        .output
        .filename("[name].[hash].js")
        .end();
    }
  },
  chainWebpack: config => {
    config.module
        .rule("vue")
        .use("vue-svg-inline-loader")
            .loader("vue-svg-inline-loader")
            .options({ /* ... */ });
  },
  configureWebpack: {
    module: {
      rules: [
        {
          exclude: /index.html/,
          loader: "vue-template-loader",
          options: {
            transformToRequire: {
              // The key should be element name,
              // the value should be attribute name or its array
              img: "src",
            },
          },
          test: /.html$/,
        },
        /*{
          loader: "file-loader",
          options: {
            name: "[name].[ext]?[hash]",
          },
          test: /\.(png|jpg|gif|svg)$/,
        },*/
        /*{
          test: /\.(svg)(\?.*)?$/,
          use: [
            {
              loader: "svg-inline-loader",
              options: {
                limit: 10000,
                name: "assets/img/[name].[hash:7].[ext]",
              },
            },
          ],
        },*/
      ],
    },
  },
  publicPath: "/",
};

To address the issue, I resorted to a CSS workaround for embedding the graphic. However, any tips related to Webpack/Vue.config.js would be greatly appreciated.

I've tried various path combinations such as ../../, ../, ./ along with @/ and ~/ before the image file location.

Answer №1

To temporarily solve the problem, I managed to find a workaround by utilizing

<img class="img-fluid" :src="require('@/assets/logo.png')" alt="CompanyLogo">
.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Webpack encounters an error due to the relocation of babel to babel-core

After trying various solutions from different developers' stackoverflow posts, none of them were successful in resolving the issue I am facing. Some of the actions I took include: uninstalling babel installing babel-core and babel-cli upgrading to n ...

Expanding the value in Vue2 using a method

I'm seeking a simple solution here. I have a single component structured like this: export default defineComponent({ name: "Home", setup() { const { pages, loading, error } = useGetPages(); return { pages, loading, error }; }, ...

Using Filepond to upload images in an Express project with EJS integration

Currently, I am working on a project that utilizes express.js for backend functionality and ejs as the rendering template for frontend. As part of this project, I have uploaded some images using filepond which were then converted to base64 format. However, ...

Tips on creating type definitions for CSS modules in Parcel?

As someone who is brand new to Parcel, I have a question that may seem naive. In my project, I am using typescript, react, less, and parcel. I am encountering an error with typescript stating 'Cannot find module 'xxx' or its corresponding t ...

Is there a disparity in capabilities or drawbacks between ViewChild and Input/Output in Angular?

As I delve into Angular ViewChild and compare it to Input/Output parameters, I can't help but wonder if ViewChild has any drawbacks or limitations compared to Input/Output. It appears that ViewChild is the preferred method, as all parameters are now ...

Is it truly possible to return a reactive variable that updates its value asynchronously?

While reviewing the code of a frontend project developed in Vue3, I came across a unique construction that I have not encountered before. This has led to some confusion as I try to grasp how it operates. The concept involves assigning the result of an asyn ...

The attribute 'randomUUID' is not found within the 'Crypto' interface

I attempted to utilize the crypto.randomUUID function in my Angular app version 13.1, however, it does not seem to be accessible. When trying to use it, I encountered this error: TS2339: Property 'randomUUID' does not exist on type 'Crypto ...

Activate a tooltip in Vuetify

I'm utilizing vuetify and have implemented a tooltip feature on a button. However, I do not want the tooltip to be displayed on hover or click; instead, I would like it to appear when a specific event is triggered. translate.vue <v-tooltip v-model ...

Is there a way to showcase just the month in one spot when presenting data using Angular 13?

Just starting out with Angular and facing a challenge in the Milestone section. There is a loop for displaying years and months, but I need to ensure that the month name is displayed only once for each specific year. Can someone provide me with a possible ...

Ensure that the MUI icon color is set accurately

I created a functional component to set default values for react-admin's BooleanField. Here is the code: import ClearIcon from '@mui/icons-material/Clear' import DoneIcon from '@mui/icons-material/Done' import get from ...

Tips for improving the readability of nested axios calls - a practical guide

I'm struggling with asynchronous Axios calls. While my nested Axios calls are functional, the code is becoming difficult to read and I often get lost in it. Currently, my structure looks like this: axios.get().then((response) => { this.pbmI ...

Ways to differentiate between the sources of two cold Observables (not just the possible data streams they may produce)

Situation: Within my Angular application, I am using publishReplay to store and replay specific Http requests. However, I encountered an issue where I need the cached observable source to update itself and create a new cached observable with publishReplay ...

Tips for transferring state information from a client to a server component within Nextjs?

Currently, I am working on a project where I need to read and write data from a locally stored .xml file that contains multiple <user> tags. The technology stack includes TypeScript and NextJS. The project is divided into three main components sprea ...

Errors encountered: Navigation guard causing infinite redirection due to unhandled runtime issue

My Vue3 router is set up with the following routes: export const routes: Array<RouteRecordRaw> = [ { path: "/", name: "Browse Questions", component: HomeView, meta: { access: "canAdmin", }, ...

Using Vue 3 or Nuxt, the v-if directive and watch property can cause issues with initializing

Visit this link: Currently using Nuxt 3.4.2 along with Supabase, I have implemented skeleton loading and pagination features. However, after adding these, the Flowbite off-canvas drawer stopped working properly. The issue arises when the data-drawer-targe ...

In order to iterate through a 'IterableIterator<number>', you must either enable the '--downlevelIteration' flag or set the '--target' to 'es2015' or newer

While attempting to enhance my Slider, I encountered an error when utilizing TypeScript React within this Next.js project: "Type 'IterableIterator' can only be iterated through when using the '--downlevelIteration' flag or with a ...

What is the most effective way to reset the v-model in the child component using the parent component?

Could you please assist me? I have been trying for 10 hours straight and it doesn't seem to work. What I am aiming for is that when I click on @click="cleanDataForm" in the Parent Component, the v-model text in the Child component will be emptied. I h ...

Mastering the use of the edit feature in Vue.js

Trying to modify a todo list by implementing a feature that displays a text input field when the edit button is toggled. However, currently, clicking the button causes the input box to appear for all todos in the list. Here's the modified code: < ...

What steps can be taken to resolve the vulnerability in webpack-pwa-manifest?

Looking for solutions to address the [email protected] and minimist vulnerability. I attempted removing node/modules and package-lock.json, followed by a fresh npm installation, but the issue persists. Any suggestions would be greatly appreciated. Scr ...

Issue with passing props to child component in React due to TypeScript error

In the process of developing an expense tracker app using react and typescript. expense_type.ts export type IState = { id : number, text : string, amount : number } export type IinitialStateType = { transactions : IState[] } expor ...