vue学习——集成sass

安装

pnpm i sass sass-loader -D

在vite.config.ts文件配置:

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 // 设置全局变量

// index.scss
@import './reset.scss'; // 注意:分号不能少!
// 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;
}
// variables.scss
$color: skyblue

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

相关推荐

  1. vue学习——集成sass

    2024-02-05 07:02:04       58 阅读
  2. vue3中集成sass实现全局scss样式变量

    2024-02-05 07:02:04       53 阅读
  3. scss sass是什么?vue环境安装sass报错

    2024-02-05 07:02:04       25 阅读
  4. Vue项目自动注入less、sassscss、stylus全局变量

    2024-02-05 07:02:04       35 阅读
  5. sass 学习笔记

    2024-02-05 07:02:04       45 阅读
  6. sass学习

    2024-02-05 07:02:04       57 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-05 07:02:04       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-05 07:02:04       106 阅读
  3. 在Django里面运行非项目文件

    2024-02-05 07:02:04       87 阅读
  4. Python语言-面向对象

    2024-02-05 07:02:04       96 阅读

热门阅读

  1. C++ Primer 第 5 版 第 5 章习题答案

    2024-02-05 07:02:04       37 阅读
  2. 网易和腾讯面试题精选---缓存面试问题和答案

    2024-02-05 07:02:04       46 阅读
  3. vue-element-admin npm install 失败解决

    2024-02-05 07:02:04       47 阅读
  4. Github使用教程

    2024-02-05 07:02:04       57 阅读
  5. 开源计算机视觉库OpenCV详细介绍

    2024-02-05 07:02:04       48 阅读
  6. CSS两侧固定,中间自适应

    2024-02-05 07:02:04       45 阅读
  7. idea后端几个层

    2024-02-05 07:02:04       53 阅读
  8. 可基于udp的可靠传输协议kcp介绍,C++测试kcp示例

    2024-02-05 07:02:04       45 阅读
  9. 【美团】酒旅用户增长-后端研发

    2024-02-05 07:02:04       45 阅读