Guide to importing a css file from node_modules in Vue component

I would like to integrate the toastr library into my component:

my-component.vue

<script>
  import toastr from 'toastr';

  export default {
    mounted(){
      toastr.success('Hello from toastr!');
    }
  }
</script>

<template>
  <div>
    Template for my-component.vue here.
  </div>
</template>


<style>
  /* How can I import `toastr.css` from node_modules in this section? */
</style>

Is there a way to link the library's CSS file located in the node_modules directory?

Answer №1

According to the suggestions from @LinusBorg in the vue-loader discussion thread found here, you can utilize the src attribute within the <style> tag:

my-component.vue

<script>
  import toastr from 'toastr';

  export default {
    mounted(){
      toastr.success('Hello from toastr!');
    }
  }
</script>

<template>
  <div>
    Template for my-component.vue here.
  </div>
</template>


<style src='toastr/build/toastr.min.css'></style>

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

How to create a CSS animation that gradually darkens a background image during a

Currently in the process of constructing a page with an intriguing background image: body { background:url(images/bg.png) center center no-repeat fixed; -webkit-background-size:cover; -moz-background-size:cover; -o-background-size:cover; ...

What is the best way to eliminate the space between the website's border and the image?

Is there a way to eliminate the space between the left and right borders? I want the picture to fill 100% of the browser window. https://i.stack.imgur.com/gqgOs.png img.test { display: block; outline: 0px; padding: 0px; margin: 0px; } <img c ...

Issues with display of Vue2-leaflet LMap/LTileLayer components

Currently, I am in the process of enhancing my Vue2 learning project by integrating a map. After exploring Google Maps, I concluded that using OSM and Leaflet would be the most suitable approach. However, I have encountered an initial obstacle where the ma ...

Can the server URL be concealed within the dist folder in Vue.js?

Currently working on a Vue.js project that will need to be distributed once development is complete. But how can I ensure its security? The js files in the "dist" folder contain the server URL, such as http://sample.org:8001/. What if a user changed all t ...

What could be causing my Array Push not to function correctly in Vue?

I have a question regarding adding simple numbers to an array and accessing the content of another array for comparison. Here is the code snippet I am working with: checkForUpdates(curr_dataset) { var current = curr_dataset; var update = []; // in ...

Unique name for the transition animation on SSR-Nuxt page transitions

Attempting to implement a dynamic transition name for Nuxt page transitions as shown below: export default{ data() { return { prevHeight: 0, transitionName: 'page' }; }, transition: { na ...

Struggling to achieve a responsive design on a webpage despite using bootstrap. Having difficulty creating a responsive layout with containers and columns

I'm fairly new to this and I've experimented with containers and rows, dividing the columns as needed. While my current setup displays a nice webpage on my pc, it still lacks responsiveness. I understand that using media tags could solve the issu ...

The Vue.js/Vuex login feature encountered an error: [vuex] The action type "postLogin" is unrecognized

I am relatively new to Vuejs and still learning Vuex. While I have a good understanding of the basics, I am facing difficulties getting my login feature to work. The error message I keep encountering is: [vuex] unknown action type: postLogin. My goal is ...

What are some ways to personalize a scrollbar?

I am looking to customize the scrollbar within a div. I attempted to modify it using the code below, but I encountered difficulties when trying to change the scroll buttons and did not achieve my desired outcome. Additionally, this customization did not wo ...

What causes a div element to not be 100% width when all its predecessors are already set to 100

Why are the divs not expanding with content even though everything is set to 100% and how can this issue be resolved? html, body { height: 100%; } body { margin: 0; padding: 0; } /* both of these are constrained to 100vh */ #root { height: 100 ...

Is it possible to export a webpage while maintaining relative paths for CSS, images, and other assets?

I am currently working on a large enterprise web application and have created a basic prototype HTML page. This page consists of a list of CSS and JS includes with minimal markup. Surprisingly, there are a total of 57 CSS includes and 271 javascript includ ...

"Exploring the method of exporting a function in Vue.js 3 using the Composition API

// Inside File2.vue <script> import { ref, computed } from 'vue'; let example = ref(1); const totalSum = computed(() => { let result = 5 + 5; return result; }); </script> <template> <div class="pa ...

Tips for dynamically adding divs inside a parent div until its width and height are fully utilized

Background: At this moment, I am in the process of creating a webpage where users will input tile width & height along with floor width & height. The aim is to calculate the area of the floor, with tiles measured in inches and the floor input measured in f ...

Display HTML element only if the class is not currently visible

Recently, I created a dynamic web page using jQuery which involves the hiding and showing of elements based on their classes. For example: <p class='lookup'>You can lookup all the values.</p> If a user is unable to perform a lookup ...

How can I modify the CSS styles for a custom jQuery widget?

I have been working on creating a custom widget with a textarea that has multiple rows. I am now looking to change the background color of this widget on the Onfocus and OnfocusOut events. Can anyone guide me on how to achieve this? <!doctype html> ...

Identify the CSS class for the ionic component on the webpage

Currently, I am in the process of developing an application using ionic 2 and angular 2. Within this app, I am utilizing the ionic 2 component known as ModalController. Unfortunately, I have encountered a challenge when attempting to adjust the size of th ...

Learn how to set up webpack or Next.js to generate a CSS file from custom Material styles and automatically inject it into the header

One of the things I've done is define some custom material styles, like this: import {createStyles, makeStyles, Theme} from '@material-ui/core/styles'; export const useStyles = makeStyles((theme: Theme) => createStyles({ fab ...

Display interactive content according to radio button selection

I have 4 boxes, labeled a,b,c,d. When the user selects box a, specific content should be loaded: If image a is picked, load content 1 If image b is picked, load content 2 If image c is picked, load content 3 If image d is picked, load content 4 I want ...

The speed of the mobile website is dragging down the user experience on my

I'm working on creating a prototype for the mobile version of a website, utilizing only jQuery and Foundation 4 with no dynamic elements. Unfortunately, when I view the site on an iPhone browser, it loads very slowly and is unresponsive to touch comma ...

Element on navigation bar extending full width of the page

As a fairly new designer, I am facing an issue with my navbar button. Currently, it is only 100 pixels wide and fixed in place, allowing the rest of the page to scroll past it. However, although it is confined to 100PX in width, it still spans across the e ...