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

Flattening an array of Map in Typescript involves combining all the

I am working with an array containing entries of type Map<string, number> Is there a way to flatten this array into a single map? Map<string, number>[] converted to Map<string, number> Appreciate any help on this matter. ...

Utilizing Vue's Watch Functionality in Conjunction with the Get and Set Composition API

I am currently working on a project that involves creating a searchable table element with the ability for users to filter and search the displayed results. However, I am encountering some difficulties in setting the value in the computed property setter. ...

Typescript: object containing at least one property with the type T assigned

Is there a method to write the HasNumber interface in Typescript without receiving an error due to the fact that the HasNumberAndString interface includes a property that is not of type number? I am looking for a way to require the HasNumberAndString int ...

Set up an array data by extracting values from an array prop within a Vue component

Within my Vue component, I am dealing with an array prop called selectedSuppliers that consists of objects. My goal is to set up a data property named suppliers and initialize it with the values from selectedSuppliers. However, I do not want any modificati ...

What is the best way to handle alias components in next.js when using ts-jest?

When working with TypeScript, Next.js, and Jest, I wanted to simplify my imports by using aliases in my tsconfig file instead of long relative paths like "../../..". It worked fine until I introduced Jest, which caused configuration issues. This is a snip ...

Is there a way to selectively display items that are grouped with children only?

I am currently experimenting with Vuetify and exploring the usage of v-list-group. I am curious to know if there is a way to prevent the grouping behavior for items that do not have any children? <template> <v-layout fill-height> ...

How can I prevent event propagation in Vuetify's v-switch component?

Currently, I am working with Vuetify and have incorporated the use of v-data-table. Whenever I click on a row within this data table, a corresponding dialog box represented by v-dialog should open. Additionally, each row contains a v-switch element. Howeve ...

Tips for transforming a JSON response into an array with JavaScript

I received a JSON response from an API: [ { "obj_Id": 66, "obj_Nombre": "mnu_mantenimiento_de_unidades", "obj_Descripcion": "Menu de acceso a Mantenimiento de Unidades" }, { "obj_Id": 67, "ob ...

Error TS2307 - Module 'lodash' not found during build process

Latest Update I must apologize for the confusion in my previous explanation of the issue. The errors I encountered were not during the compilation of the Angular application via Gulp, but rather in the Visual Studio 'Errors List'. Fortunately, I ...

Establishing the types of object properties prior to performing a destructuring assignment

Consider a scenario where a function is utilized to return an object with property types that can be inferred or explicitly provided: const myFn = (arg: number) => { return { a: 1 + arg, b: 'b' + arg, c: (() => { ...

Converting a specific string format to a Date object in TypeScript

I am in need of a solution to convert strings with the given format into Date objects using TypeScript: var dateTimeString:string = "20231002-123343" I have created my own method as shown below: var dateTime:string[] = dateTimeString.split(" ...

Divide a single image into several smaller images and enable clickable links on each separate image, similar to an interactive image map

Challenge: I am faced with the task of splitting a large image (1920px x 1080px) into smaller 40px by 40px images to be displayed on a webpage. These smaller images should come together seamlessly to recreate the original full-size image, with 48 images a ...

Unable to transfer PNG files using the express route

I am facing an issue with rendering a PNG image served from my express endpoint. I have the image stored as a buffer in node, but despite my efforts, I am unable to display it correctly on the webpage. Current Situation https://i.stack.imgur.com/vRQjB.pn ...

"Exploring the method to navigate through a nested Firebase collection linked to its parent collection

I have a forum application in development where users can ask questions and receive answers, each answer having its own 'like' feature. I am trying to access the 'likes' subcollection when viewing an answer, but I am unsure of how to do ...

Flow - secure actions to ensure type safety

Currently implementing flow and looking to enhance the type safety of my reducers. I stumbled upon a helpful comment proposing a solution that seems compatible with my existing codebase: https://github.com/reduxjs/redux/issues/992#issuecomment-191152574 I ...

Error in React Component Library: The identifier 'Template' was not expected. Instead, '}' is expected to end an object literal

I've embarked on the exciting journey of creating my own React component library. Utilizing a helpful template found here, I've shaped the latest iteration of my library. To test its functionality, I smoothly execute the storybook with yarn stor ...

Steps to troubleshoot the TypeError: cv.Mat is not a constructor in opencv.js issue

Encountering a problem while trying to use opencv.js for detecting aruco markers from my camera. Each time I attempt to utilize the method let image = new cv.imread('img'); An error keeps popping up: TypeError: cv.Mat is not a constructor ...

How should dynamic route pages be properly managed in NextJS?

Working on my first project using NextJS, I'm curious about the proper approach to managing dynamic routing. I've set up a http://localhost:3000/trips route that shows a page with a list of cards representing different "trips": https://i.stack. ...

Suggestions for managing the window authentication popup in Protractor when working with Cucumber and TypeScript?

I'm a beginner with Protractor and I'm working on a script that needs to handle a window authentication pop-up when clicking on an element. I need to pass my user id and password to access the web page. Can someone guide me on how to handle this ...

Tips for capturing an error generated by a child component's setter?

I've created an App component that contains a value passed to a Child component using the @Input decorator. app.component.html <app-child [myVariable]="myVariable"></app-child> app.component.ts @Component(...) export class AppC ...