Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to import all css of node_modules in vuejs

I am building a Vue.js app starting with the webpack template and vuetify. To import vuetify css Im doing this in my App.vue

<style> @import '../node_modules/vuetify/dist/vuetify.min.css' </style>

Is this the correct or only way? because it doesn't seem reliable when using multiple UI components.

like image 333
Diego Manjarrés Avatar asked Jul 08 '17 04:07

Diego Manjarrés


People also ask

How do I import 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.

How do I import CSS into vue3?

Importing CSS in Vue components If you are setup and using webpack, you should be able to import css directly from inside <style> tags in component files. More info here: https://cli.vuejs.org/guide/css.html. https://github.com/vuejs/vue-loader.

How do I import custom components to Vue?

STEP 01: First, Import the Child Component into the Parent Component inside script tag but above export default function declaration. STEP 02: Then, Register the Child Component inside the Parent Component by adding it to components object. STEP 03: Finally, Use the Child Component in the Parent Component Template.


1 Answers

You can import it in yout main.js

import 'vuetify/dist/vuetify.min.css'

for this to work you should have css-loader in you webpack config

In your webpack

module: {
  loaders: [
    { test: /\.css$/, loader: "css-loader" }
  ]
}

OR

In your App.vue component add two style tags , one for global styles as App.vue is the entry point and other for scoped styles if you have any with the scoped attribute.See src imports.

<style src='vuetify/dist/vuetify.min.css'>
    /* global styles */
</style> 

<style scoped>
    /* local styles */
</style> 
like image 71
Vamsi Krishna Avatar answered Sep 22 '22 13:09

Vamsi Krishna