Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import css file from node_modules in Vue-component

I want to connect this 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 TO IMPORT `toastr.css` FROM NODE_MODULES HERE?
</style>

How to connect library's css from node_modules directory?

like image 437
Peter Zaitsev Avatar asked Nov 18 '17 11:11

Peter Zaitsev


People also ask

How do I import CSS into app Vue?

There are multiple ways of including a css file in your vue app. The way I prefer is to have a single css file import inside the main. js file for your vue app. You can have multiple scss/css files which you can import in this main/styles.

Where do I put global CSS in Vue?

To add global CSS in Vue. js, we can import our global CSS file in main. js . import "./assets/css/main.

Does Vue have CSS?

Vue has three common approaches to styling apps: External CSS files. Global styles in Single File Components ( . vue files).


1 Answers

As @LinusBorg suggested here in vue-loader discussion thread, you can use src-attribute inside <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>
like image 56
hedin Avatar answered Sep 21 '22 11:09

hedin