vue学习——集成sass

安装

bash 复制代码
pnpm i sass sass-loader -D

在vite.config.ts文件配置:

bash 复制代码
export default defineConfig({
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: '@import "./src/styles/variable.scss";',
        },
      },
    },
    }
}

创建三个文件

src/styles/index.scss // 公共样式

src/styles/reset.scss // 清除默认样式

src/styles/variables.scss // 设置全局变量

bash 复制代码
// index.scss
@import './reset.scss'; // 注意:分号不能少!
bash 复制代码
// reset.scss
// 去npm中搜索reset.scss放到这里
/**
 * ENGINE
 * v0.2 | 20150615
 * License: none (public domain)
 */

*,
*:after,
*:before {
  box-sizing: border-box;

  outline: none;
}

html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
  font: inherit;
  font-size: 100%;

  margin: 0;
  padding: 0;

  vertical-align: baseline;

  border: 0;
}

article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
  display: block;
}

body {
  line-height: 1;
}

ol,
ul {
  list-style: none;
}

blockquote,
q {
  quotes: none;
  &:before,
  &:after {
    content: '';
    content: none;
  }
}

sub,
sup {
  font-size: 75%;
  line-height: 0;

  position: relative;

  vertical-align: baseline;
}
sup {
  top: -.5em;
}
sub {
  bottom: -.25em;
}

table {
  border-spacing: 0;
  border-collapse: collapse;
}

input,
textarea,
button {
  font-family: inhert;
  font-size: inherit;

  color: inherit;
}

select {
  text-indent: .01px;
  text-overflow: '';

  border: 0;
  border-radius: 0;

  -webkit-appearance: none;
  -moz-appearance: none;
}
select::-ms-expand {
  display: none;
}

code,
pre {
  font-family: monospace, monospace;
  font-size: 1em;
}
bash 复制代码
// variables.scss
$color: skyblue

App.vue中测试一下,是否已清除默认样式,全局变量是否生效。

相关推荐
前端熊猫1 小时前
排序算法学习笔记
笔记·学习·排序算法
auspark1 小时前
macos下cocoapods的学习
学习·macos·cocoapods
朔北之忘 Clancy2 小时前
2022 年 12 月青少年软编等考 C 语言五级真题解析
c语言·开发语言·c++·学习·算法·青少年编程·题解
宋隽颢3 小时前
STM32学习【4】ARM汇编(够用)
arm开发·stm32·学习
我哪天都没空3 小时前
【蓝桥杯嵌入式】各模块学习总结
笔记·学习·蓝桥杯
ILUUSION_S3 小时前
学习路程五 向量数据库Milvus操作
数据库·python·学习·langchain·milvus
谏君之3 小时前
编写第一个 C++ 程序 – Hello World 示例
开发语言·c++·单片机·学习
LuckyLay4 小时前
Golang学习笔记_40——模版方法模式
笔记·学习·设计模式·golang·模板方法模式
s_little_monster4 小时前
【Linux】进程间通信之匿名管道
linux·运维·服务器·数据库·经验分享·笔记·学习
EnigmaCoder6 小时前
C语言【进阶篇】之指针——涵盖基础、数组与高级概念
c语言·开发语言·学习