KrishanK's avatar

Deal with vuejs latency

Hey guys,

My Problem:

I am new to Vuejs, so I started by creating a Modal-Component like @JeffreyWay does in Vue 2.0 step by step - named slots video. Everything works fine, but there is a small issue. When I define a default slot and paste my main content between my modal-tags and reload the page I can catch a small glimpse on the modal text. After milliseconds it is gone.

What I found:

After a bit of research I found the following in the vue-documentation - Extracting Component Css:

When using Single-File Components, the CSS inside components are injected dynamically as tags via JavaScript. This has a small runtime cost, and if you are using server-side rendering it will cause a “flash of unstyled content”. Extracting the CSS across all components into the same file and avoid these issues, and also result in better CSS minification and caching.

I tried to use the suggested approach and created a webpack.config.js file with this content:

// webpack.config.js
var ExtractTextPlugin = require("extract-text-webpack-plugin")

module.exports = {
  // other options...
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue',
        options: {
          loaders: {
            css: ExtractTextPlugin.extract({
              loader: 'css-loader',
              fallbackLoader: 'vue-style-loader' // <- this is a dep of vue-loader, so no need to explicitly install if using npm3
            })
          }
        }
      }
    ]
  },
  plugins: [
    new ExtractTextPlugin("style.css")
  ]
}

Since laravel-elixir reads all webpack.config.js files, I thought it might work this way. However it did not.

Would appreciate if someone could help :).

EDIT

I replaced the default slot with a named slot, now my modal content does not display anymore on the site. However I still do not know how to extract the Component CSS...

0 likes
9 replies
ejdelmonico's avatar

You are not required to put styles in your component. You can leave them out and just place any classes you will need on the tags. Then, just write the css in you main style sheet. I would avoid making everything complicated.

KrishanK's avatar

@ejdelmonico I know it is not required, but I am curious about how to extract css styles from a vue component. Is it possible with elixir/ will it be possible with mix?

ChuiSauCE's avatar

@Naoray you've found any configuration for it? I'm new with Vue too. I don't wanna dive into webpack since had no exparience but using webpack.mix file :). Hope you found the way and can share it

KrishanK's avatar

@ChuiSauCE no sorry. I did just accept that my modal texts are shown for milliseconds.

What is your exact problem?

ChuiSauCE's avatar

@Naoray every single style of component being injected to head seperatly. I wanna have an external style sheet that comes out of components.

Basicly once i compile .vue files, i wanna have app.js and app.css ^^

sdebacker's avatar

It is possible with Laravel Mix by setting extractVueStyles to true in your webpack.mix.js file:

mix.options({ extractVueStyles: true });
1 like
KrishanK's avatar
KrishanK
OP
Best Answer
Level 14

For every other who might come across the described problem.

Just add v-cloak to your root vue html element.

<div id="app" v-cloak>

</div>

Now add [v-cloak] {display: none} to your stylesheet.

Source: Vuejs Documentation

Please or to participate in this conversation.