Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 升级vite5.4 ,sass1.83, 启用sass 现代Api,减少不必要的warnning, 弃用 @import指令,改用@use 和@forward指令 #3239

Open
wants to merge 5 commits into
base: v4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"@nutui/icons-vue": "^0.1.1",
"@nutui/icons-vue-taro": "^0.0.9",
"@nutui/touch-emulator": "workspace:^",
"sass": "^1.77.6",
"sass": "^1.83.0",
"vue-router": "^4.4.0"
},
"devDependencies": {
Expand Down Expand Up @@ -109,7 +109,7 @@
"rimraf": "^6.0.0",
"typescript": "^5.4.5",
"unplugin-vue-components": "^0.27.2",
"vite": "^5.3.2",
"vite": "^5.4.11",
"vite-plugin-vue-devtools": "^7.2.1",
"vitest": "^2.0.1",
"vitest-canvas-mock": "^0.3.3",
Expand Down
665 changes: 570 additions & 95 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion scripts/generate-nutui-taro-vue.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ config.nav.map((item) => {
}.vue'\n`
}
}
importScssStr += `import './__VUE/${name.toLowerCase()}/index.scss'\n`
importScssStr += `@use './__VUE/${name.toLowerCase()}/index.scss' as ${name.toLowerCase()}\n`
if (exclude !== true) {
packages.push(name)
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-nutui.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ config.nav.map((item) => {
methods.push(`show${name}`)
}
}
importScssStr += `import './__VUE/${name.toLowerCase()}/index.scss'\n`
importScssStr += `@use './__VUE/${name.toLowerCase()}/index.scss' as ${name.toLowerCase()}\n`
if (exclude != true) {
packages.push(name)
}
Expand Down
26 changes: 14 additions & 12 deletions scripts/generate-themes.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ const sass = require('sass')

let sassFileStr = ``
let tasks = []
if (!target) {
sassFileStr += `@import '@nutui/icons-vue/dist/style_icon.css';\n`
}

config.nav.map((item) => {
item.packages.forEach((element) => {
let folderName = element.name.toLowerCase()
if (element.exclude != true) {
sassFileStr += `@import '../../packages/${folderName}/index.scss';\n`
sassFileStr += `@use '../../packages/${folderName}/index.scss' as ${folderName};\n`
}
tasks.push(
fs
Expand All @@ -27,6 +25,10 @@ config.nav.map((item) => {
)
})
})
// use指令必须在前面,否则会报错
if (!target) {
sassFileStr += `@import '@nutui/icons-vue/dist/style_icon.css';\n`
}

tasks.push(fs.copy(path.resolve(__dirname, '../src/packages/styles'), path.resolve(__dirname, '../dist/styles')))

Expand All @@ -49,7 +51,7 @@ const sassTocss = () => {
// 写入main.scss,引入变量文件variables.scss和组件样式index.scss
fs.outputFile(
filePath,
`@import '../../styles/variables.scss';\n@import './index.scss';\n`,
`@use '../../styles/variables.scss' as vars;\n@use './index.scss';\n`,
'utf8',
(error) => {
if (error) return console.error(error)
Expand Down Expand Up @@ -101,11 +103,11 @@ const parseFile = (filename, theme = 'default') => {
}
})

let fileContent = `@import './${themesEnum[theme]}.scss';\n:root {\n`
let fileContent = `@use './${themesEnum[theme]}.scss' as vars;\n:root {\n`
for (const key in variables) {
if (Object.prototype.hasOwnProperty.call(variables, key)) {
const variableName = key.slice(1)
fileContent += ` --nut-${variableName}: #{$${variableName}};\n`
fileContent += ` --nut-${variableName}: #{vars.$${variableName}};\n` // 使用 vars.$variableName
}
}
fileContent += `}`
Expand Down Expand Up @@ -138,10 +140,10 @@ const variablesResolver = () => {

Promise.all(tasks).then(() => {
let themes = [
{ file: 'default.scss', sourcePath: `@import '../variables.scss';` },
{ file: 'jdt.scss', sourcePath: `@import '../variables-jdt.scss';` },
{ file: 'jdb.scss', sourcePath: `@import '../variables-jdb.scss';` },
{ file: 'jddkh.scss', sourcePath: `@import '../variables-jddkh.scss';` }
{ file: 'default.scss', sourcePath: `@use '../variables.scss' as vars;` },
{ file: 'jdt.scss', sourcePath: `@use '../variables-jdt.scss' as vars;` },
{ file: 'jdb.scss', sourcePath: `@use '../variables-jdb.scss' as vars;` },
{ file: 'jddkh.scss', sourcePath: `@use '../variables-jddkh.scss' as vars;` }
]
tasks = []
themes.forEach((item) => {
Expand All @@ -161,4 +163,4 @@ Promise.all(tasks).then(() => {
sassTocss()
variablesResolver()
})
})
})
32 changes: 16 additions & 16 deletions src/packages/__VUE/actionsheet/index.scss
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
@import '../popup/index.scss';
@use '../../styles/variables.scss' as vars;

.nut-theme-dark {
.nut-action-sheet {
.nut-action-sheet__cancel {
border-top: 1px solid $dark-background2;
border-top: 1px solid vars.$dark-background2;
}
.nut-action-sheet__title {
border-bottom: 1px solid $dark-background2;
border-bottom: 1px solid vars.$dark-background2;
}
.nut-action-sheet__cancel,
.nut-action-sheet__item,
.nut-action-sheet__title {
background: $dark-background;
color: $dark-color;
background: vars.$dark-background;
color: vars.$dark-color;
}
}
}
Expand All @@ -24,10 +24,10 @@
padding: 10px;
margin: 0;
text-align: center;
background-color: $white;
border-bottom: 1px solid $actionsheet-light-color;
font-size: $font-size-base;
color: $title-color;
background-color: vars.$white;
border-bottom: 1px solid vars.$actionsheet-light-color;
font-size: vars.$font-size-base;
color: vars.$title-color;
}
.nut-action-sheet__menu {
display: block;
Expand All @@ -40,24 +40,24 @@
.nut-action-sheet__item {
display: block;
padding: 10px;
line-height: $actionsheet-item-line-height;
font-size: $actionsheet-item-font-size;
color: $actionsheet-item-font-color;
line-height: vars.$actionsheet-item-line-height;
font-size: vars.$actionsheet-item-font-size;
color: vars.$actionsheet-item-font-color;
text-align: center;
background-color: #fff;
border-bottom: $actionsheet-item-border-bottom;
border-bottom: vars.$actionsheet-item-border-bottom;
cursor: pointer;
}

.nut-action-sheet__desc {
font-size: $actionsheet-item-font-size;
font-size: vars.$actionsheet-item-font-size;
color: #999;
cursor: default;
}

.nut-action-sheet__subdesc {
display: block;
font-size: $actionsheet-item-subdesc-font-size;
font-size: vars.$actionsheet-item-subdesc-font-size;
color: #999;
}

Expand All @@ -71,6 +71,6 @@

.nut-action-sheet__cancel {
margin-top: 5px;
border-top: $actionsheet-item-cancel-border-top;
border-top: vars.$actionsheet-item-cancel-border-top;
}
}
53 changes: 26 additions & 27 deletions src/packages/__VUE/address/index.scss
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
@import '../popup/index.scss';
@import '../elevator/index.scss';
@use '../../styles/variables.scss' as vars;

.nut-theme-dark {
.nut-address {
&__header {
color: $dark-color;
color: vars.$dark-color;

&__title {
color: $dark-color;
color: vars.$dark-color;
}
}

.nut-address__custom {
.nut-address__region {
color: $dark-color;
color: vars.$dark-color;
}
.nut-address__detail {
.nut-address__detail-list {
.nut-address__detail-item {
color: $dark-color;
color: vars.$dark-color;
}
}
}
Expand All @@ -28,17 +27,17 @@
.nut-address__exist-group {
.nut-address__exist-group-list {
.nut-address__exist-group-item {
color: $dark-color;
color: vars.$dark-color;
}
}
}

.nut-address__exist-choose {
border-top: 1px solid $dark-background;
border-top: 1px solid vars.$dark-background;
}
}
&-custom-buttom {
border-top: 1px solid $dark-background;
border-top: 1px solid vars.$dark-background;
}
}
}
Expand All @@ -56,8 +55,8 @@
color: #333;
&__title {
display: block;
color: $address-header-title-color;
font-size: $address-header-title-font-size;
color: vars.$address-header-title-color;
font-size: vars.$address-header-title-font-size;
}
}

Expand All @@ -69,16 +68,16 @@
// margin-top: 32px;
padding: 0 20px;
display: flex;
font-size: $address-region-tab-font-size;
color: $address-region-tab-color;
font-size: vars.$address-region-tab-font-size;
color: vars.$address-region-tab-color;

.nut-address__region-item {
position: relative;
min-width: 2px;
margin-right: 30px;
display: block;
&.active {
font-weight: $address-region-tab-active-item-font-weight;
font-weight: vars.$address-region-tab-active-item-font-weight;
}

view {
Expand All @@ -105,7 +104,7 @@
margin-top: 5px;
width: 0;
height: 3px;
background: $address-region-tab-line;
background: vars.$address-region-tab-line;
transition: 0.2s all linear;

&.active {
Expand All @@ -122,10 +121,10 @@
margin-top: 5px;
width: 26px;
height: 3px;
background: $address-region-tab-line;
background: vars.$address-region-tab-line;
transition: 0.2s all linear;
border-radius: $address-region-tab-line-border-radius;
opacity: $address-region-tab-line-opacity;
border-radius: vars.$address-region-tab-line-border-radius;
opacity: vars.$address-region-tab-line-opacity;
}
}

Expand All @@ -142,8 +141,8 @@
display: flex;
align-items: center;

font-size: $address-region-item-font-size;
color: $address-region-item-color;
font-size: vars.$address-region-item-font-size;
color: vars.$address-region-item-color;
&.active {
font-weight: bold;
}
Expand Down Expand Up @@ -178,15 +177,15 @@
display: flex;
align-items: center;
margin-bottom: 20px;
font-size: $font-size-1;
font-size: vars.$font-size-1;
line-height: 14px;
color: #333;
&.active {
font-weight: bold;
}
.exist-item-icon {
margin-right: $address-item-margin-right;
color: $address-icon-color !important;
margin-right: vars.$address-item-margin-right;
color: vars.$address-icon-color !important;
}
span {
display: inline-block;
Expand All @@ -207,16 +206,16 @@
line-height: 42px;
margin: auto;
text-align: center;
background: $button-primary-background-color;
background: vars.$button-primary-background-color;
border-radius: 21px;
font-size: 15px;
color: $white;
color: vars.$white;
}
}
}

&-select-icon {
margin-right: $address-item-margin-right;
color: $address-icon-color !important;
margin-right: vars.$address-item-margin-right;
color: vars.$address-icon-color !important;
}
}
Loading