Skip to content

Commit 0dbb602

Browse files
committed
sass: replace deprecated @import with @use, plus...
Also, assume project root dir is in load path, remove leading / However, see differences from @import https://sass-lang.com/documentation/at-rules/use/#differences-from-import
1 parent 8264002 commit 0dbb602

File tree

8 files changed

+101
-63
lines changed

8 files changed

+101
-63
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
## TODO:
2+
Use `--fatal-deprecation=import` to prevent any regressive use of @import - this will treat any sass @import rules as errors.
3+
4+
Whilst the changed sass seems to be working fine, it's _possible_ that in our astro config, within `vite: {}`, we will want to tell sass to look in the project root when we use @use without an absolute path. e.g. `@use "styles/variables.scss"`
5+
```json
6+
css: {
7+
preprocessorOptions: {
8+
scss: {
9+
// This tells Sass to look in the project root for any @use paths
10+
loadPaths: [path.resolve('./')],
11+
},
12+
},
13+
},
14+
```
15+
This will also need `import path from 'path';`
16+
17+
18+
## notes
19+
change: moved from use of @import to @use
20+
reason: lots of noisy deprecation warnings about our use of @import, when running the astro site.
21+
change 2: changed paths from `/styles/variables.scss` to `styles/variables.scss`
22+
23+
24+
process:
25+
26+
read: https://sass-lang.com/blog/import-is-deprecated/
27+
read: https://sass-lang.com/documentation/at-rules/use/#differences-from-import
28+
29+
used
30+
```
31+
npx sass-migrator module --migrate-deps --load-path=. "styles/*.scss"
32+
```
33+
* The migrator failed because it couldn't parse .astro files
34+
* Manually updated the @import to @use in Astro components (only one, at the time, HomepageLayout)
35+
* ran the migrator
36+
* checked that multiple uses of @use aren't causing the same large chunk of html to be copied to output css files.
37+
* it may still be worth a split of variables.scss to separate the sass variables - which may be imported with @use in many places,from the rest of the css variables defined in there, which can be loaded in just once to some sort of base css file.
38+

src/components/Dropdown/styles.module.scss

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import "/styles/variables.scss";
1+
@use "styles/variables.scss";
22

33
.container {
44
position: relative;
@@ -62,11 +62,11 @@
6262
.icon {
6363
left: 10px;
6464
top: 8px;
65-
@media (min-width: $breakpoint-tablet) {
65+
@media (min-width: variables.$breakpoint-tablet) {
6666
left: 11px;
6767
top: 8px;
6868
}
69-
@media (min-width: $breakpoint-desktop) {
69+
@media (min-width: variables.$breakpoint-desktop) {
7070
left: 11px;
7171
top: 10px;
7272
}
@@ -76,7 +76,7 @@
7676
left: 10px;
7777
top: 8px;
7878

79-
@media (min-width: $breakpoint-laptop) {
79+
@media (min-width: variables.$breakpoint-laptop) {
8080
left: 11px;
8181
top: 10px;
8282
}
@@ -85,11 +85,11 @@
8585
.chevron {
8686
right: 10px;
8787
top: 12px;
88-
@media (min-width: $breakpoint-tablet) {
88+
@media (min-width: variables.$breakpoint-tablet) {
8989
right: 12px;
9090
top: 14px;
9191
}
92-
@media (min-width: $breakpoint-desktop) {
92+
@media (min-width: variables.$breakpoint-desktop) {
9393
right: 12px;
9494
top: 16px;
9595
}
@@ -125,7 +125,7 @@ button.chevron {
125125
// 0.75rem font-size for mobile to fit content in smaller screens
126126
font-size: 0.75rem;
127127

128-
@media (min-width: $breakpoint-tablet) {
128+
@media (min-width: variables.$breakpoint-tablet) {
129129
font-size: 1rem;
130130
padding-right: 10px;
131131
}

src/components/Nav/styles.module.scss

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
@import "/styles/variables.scss";
2-
@import "/styles/global.scss";
1+
@use "styles/variables.scss";
2+
@use "styles/global.scss";
33

44
.container {
55
height: fit-content;
66

7-
@media (min-width: $breakpoint-tablet) {
7+
@media (min-width: variables.$breakpoint-tablet) {
88
position: fixed;
99
border-right-width: 1px;
1010
border-color: var(--sidebar-type-color);
@@ -49,7 +49,7 @@
4949
margin-bottom: var(--spacing-xs);
5050
}
5151

52-
@media (min-width: $breakpoint-tablet) {
52+
@media (min-width: variables.$breakpoint-tablet) {
5353
display: grid;
5454
grid-auto-flow: column;
5555
grid-template-columns: 1fr;
@@ -104,14 +104,14 @@
104104
height: 1rem;
105105
width: 1.25rem;
106106
}
107-
@media (min-width: $breakpoint-tablet) {
107+
@media (min-width: variables.$breakpoint-tablet) {
108108
display: none !important;
109109
}
110110
}
111111

112112
.desktopMenuLabel {
113113
display: none;
114-
@media (min-width: $breakpoint-tablet) {
114+
@media (min-width: variables.$breakpoint-tablet) {
115115
display: block;
116116
margin-top: 7.5px;
117117
}
@@ -122,7 +122,7 @@
122122
display: flex;
123123
}
124124
.desktopMenuLabel {
125-
@media (min-width: $breakpoint-tablet) {
125+
@media (min-width: variables.$breakpoint-tablet) {
126126
display: none;
127127
}
128128
}
@@ -175,7 +175,7 @@
175175
padding: var(--spacing-xs) 1.25rem;
176176
}
177177

178-
@media (min-width: $breakpoint-tablet) {
178+
@media (min-width: variables.$breakpoint-tablet) {
179179
height: fit-content;
180180
border-top-width: 1px;
181181
margin-top: auto;
@@ -217,7 +217,7 @@
217217
line-height: 1.167;
218218
-webkit-text-stroke-width: 0.15px;
219219

220-
@media (min-width: $breakpoint-tablet) {
220+
@media (min-width: variables.$breakpoint-tablet) {
221221
font-size: 1.25rem;
222222
line-height: 1.2;
223223
-webkit-text-stroke-width: 0.15px;
@@ -244,7 +244,7 @@
244244
-webkit-text-stroke-width: 0.05px;
245245
}
246246

247-
@media (min-width: $breakpoint-tablet) {
247+
@media (min-width: variables.$breakpoint-tablet) {
248248
&:global(.small) {
249249
// text-body-caption
250250
font-size: 0.875rem;
@@ -270,7 +270,7 @@
270270
flex-grow: 1;
271271
height: unset;
272272

273-
@media (min-width: $breakpoint-tablet) {
273+
@media (min-width: variables.$breakpoint-tablet) {
274274
height: 100%;
275275
overflow-y: scroll;
276276

src/components/Settings/styles.module.scss

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
@import "/styles/variables.scss";
1+
@use "styles/variables.scss";
22

33
.container {
44
position: relative;
5-
@media (min-width: $breakpoint-tablet) {
5+
@media (min-width: variables.$breakpoint-tablet) {
66
margin-top: 0;
77
}
88
}
@@ -19,18 +19,18 @@
1919
row-gap: 20px;
2020
column-gap: 40px;
2121

22-
@media (min-width: $breakpoint-tablet) {
22+
@media (min-width: variables.$breakpoint-tablet) {
2323
width: calc(100% - var(--nav-offset-x));
2424
padding: 1.25rem var(--spacing-lg) var(--spacing-sm);
2525
}
2626

27-
@media (min-width: $breakpoint-laptop) {
27+
@media (min-width: variables.$breakpoint-laptop) {
2828
grid-template-columns: repeat(9, minmax(0, 1fr));
2929
gap: 40px;
3030
grid-template-rows: var(--settings-container-height-laptop);
3131
}
3232

33-
@media (min-width: $breakpoint-desktop) {
33+
@media (min-width: variables.$breakpoint-desktop) {
3434
grid-template-columns: repeat(12, minmax(0, 1fr));
3535
}
3636
}
@@ -44,10 +44,10 @@
4444
.localeselect,
4545
.a11yselect {
4646
grid-column: span 3;
47-
@media (min-width: $breakpoint-tablet) {
47+
@media (min-width: variables.$breakpoint-tablet) {
4848
grid-column: span 3;
4949
}
50-
@media (min-width: $breakpoint-laptop) {
50+
@media (min-width: variables.$breakpoint-laptop) {
5151
grid-column: span 3;
5252
}
5353
}
@@ -56,16 +56,16 @@
5656
grid-column: span 6;
5757
grid-row: 1;
5858

59-
@media (min-width: $breakpoint-tablet) {
59+
@media (min-width: variables.$breakpoint-tablet) {
6060
grid-column: span 6;
6161
}
6262

63-
@media (min-width: $breakpoint-laptop) {
63+
@media (min-width: variables.$breakpoint-laptop) {
6464
grid-row: unset;
6565
grid-column: span 3;
6666
}
6767

68-
@media (min-width: $breakpoint-desktop) {
68+
@media (min-width: variables.$breakpoint-desktop) {
6969
grid-column: span 6;
7070
}
7171
}
@@ -96,14 +96,14 @@
9696

9797
.container:global(.noJumpTo) .wrapper:global(.open) {
9898
top: 40px;
99-
@media (min-width: $breakpoint-tablet) {
99+
@media (min-width: variables.$breakpoint-tablet) {
100100
top: 0px;
101101
}
102102
}
103103

104104
.wrapper:global(.open) {
105105
top: 80px;
106-
@media (min-width: $breakpoint-tablet) {
106+
@media (min-width: variables.$breakpoint-tablet) {
107107
top: 0px;
108108
}
109109
}

src/layouts/HomepageLayout.astro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,10 @@ setJumpToState(null);
104104
</BaseLayout>
105105

106106
<style lang="scss">
107-
@import "../../styles/variables.scss";
107+
@use "styles/variables.scss";
108108
h2 {
109109
@apply mb-sm mt-0;
110-
@media (min-width: $breakpoint-tablet) {
110+
@media (min-width: variables.$breakpoint-tablet) {
111111
font-size: 3.5rem;
112112
}
113113
}

styles/base.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import "./variables.scss";
2-
@import "./global.scss";
3-
@import "./code-editor.scss";
4-
@import "./markdown.scss";
1+
@use "variables.scss";
2+
@use "global.scss";
3+
@use "code-editor.scss";
4+
@use "markdown.scss";

0 commit comments

Comments
 (0)