Peter Zaitsev
Peter Zaitsev

Reputation: 77

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?

Upvotes: 6

Views: 8412

Answers (1)

hedin
hedin

Reputation: 1024

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>

Upvotes: 13

Related Questions