Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I correct the css compile order with webpack in Vuejs?

I have a issue about css compile order in Webpack 2 with vue-cli project.

In main.js, I imported a css library file named skeleton.css . This include <a> color style.

import Vue from 'vue'
import App from './App'
import router from './router'
import 'skeleton-css/css/skeleton.css'

In App.vue, I set <a> color style as below

<style lang="scss">
    a {
        text-decoration: none;
        color: #2c3e50;
    }
</style>

When I compiled the code and open the chrome inspector. I found the wrong order insert style.

<style type="text/css">....</style> // App.vue inline style
<style type="text/css">....</style> // skeleton.css style

And my webpack 2 config with vue-cli

{
    test: /\.scss$/,
    use: [{
        loader: "style-loader"
    }, {
        loader: "css-loader"
    }, {
        loader: "sass-loader"
    }]
}

How should I do to adjust correct import style order?

like image 731
tommychoo Avatar asked Dec 24 '22 18:12

tommychoo


1 Answers

You need reorder the imports in your main.js, since it is the only thing that affects the order of <style> tags in the resulting DOM:

import 'skeleton-css/css/skeleton.css'
import Vue from 'vue'
import App from './App'
import router from './router'

Now skeleton.css comes first, and everything else would come after it.

like image 198
zerkms Avatar answered Dec 26 '22 08:12

zerkms