如何在 Vuejs 中使用 webpack 更正 css 编译顺序? [英] How do I correct the css compile order with webpack in Vuejs?
问题描述
我在使用 vue-cli 项目的 Webpack 2 中遇到了关于 css 编译顺序的问题.
I have a issue about css compile order in Webpack 2 with vue-cli project.
在 main.js 中,我导入了一个名为 skeleton.css
的 css 库文件.这包括 颜色样式.
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>
当我编译代码并打开 Chrome 检查器时.我发现了错误的订单插入样式.
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
我的 webpack 2 配置和 vue-cli
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?
推荐答案
您需要对 main.js
中的 imports
重新排序,因为它是唯一影响 标签在结果 DOM 中的顺序:
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'
现在 skeleton.css
排在第一位,其他一切都在它之后.
Now skeleton.css
comes first, and everything else would come after it.
这篇关于如何在 Vuejs 中使用 webpack 更正 css 编译顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!