refactor: use SASS @use over @import

This commit is contained in:
2024-11-13 23:16:35 +01:00
parent ac3070b0b7
commit cbd1062d82
20 changed files with 66 additions and 38 deletions

View File

@@ -20,7 +20,7 @@
"embla-carousel": "^8.3.1", "embla-carousel": "^8.3.1",
"focus-visible": "^5.2.1", "focus-visible": "^5.2.1",
"lenis": "^1.1.16", "lenis": "^1.1.16",
"motion": "^10.18.0", "motion": "^10",
"ogl": "^1.0.9", "ogl": "^1.0.9",
"sanitize.css": "^13.0.0", "sanitize.css": "^13.0.0",
"swell-js": "^4.2.4", "swell-js": "^4.2.4",
@@ -30,7 +30,7 @@
"devDependencies": { "devDependencies": {
"@sveltejs/adapter-auto": "^3.3.1", "@sveltejs/adapter-auto": "^3.3.1",
"@sveltejs/adapter-cloudflare": "^4.7.4", "@sveltejs/adapter-cloudflare": "^4.7.4",
"@sveltejs/kit": "^2.8.0", "@sveltejs/kit": "^2.8.1",
"@typescript-eslint/eslint-plugin": "^8.14.0", "@typescript-eslint/eslint-plugin": "^8.14.0",
"@typescript-eslint/parser": "^8.14.0", "@typescript-eslint/parser": "^8.14.0",
"base-64": "^1.0.0", "base-64": "^1.0.0",
@@ -44,8 +44,8 @@
"postcss-normalize": "^13.0.1", "postcss-normalize": "^13.0.1",
"postcss-preset-env": "^10.1.0", "postcss-preset-env": "^10.1.0",
"postcss-sort-media-queries": "^5.2.0", "postcss-sort-media-queries": "^5.2.0",
"sass": "^1.80.6", "sass": "^1.80.7",
"svelte": "^5.1.15", "svelte": "^5.1.16",
"svelte-check": "^4.0.7", "svelte-check": "^4.0.7",
"svelte-preprocess": "^6.0.3", "svelte-preprocess": "^6.0.3",
"tslib": "^2.8.1", "tslib": "^2.8.1",

View File

@@ -15,6 +15,7 @@
</style> </style>
<script lang="ts"> <script lang="ts">
import 'sanitize.css'
import '../style/global.scss' import '../style/global.scss'
import { PUBLIC_ANALYTICS_DOMAIN } from '$env/static/public' import { PUBLIC_ANALYTICS_DOMAIN } from '$env/static/public'
@@ -94,7 +95,7 @@
<svelte:window bind:innerHeight /> <svelte:window bind:innerHeight />
<svelte:head> <svelte:head>
<link rel="canonical" href={$page.url.href} /> <link rel="canonical" href={$page.url.href.split('#')[0]} />
{#each fonts as font} {#each fonts as font}
<link rel="preload" href="/fonts/{font}.woff2" as="font" type="font/woff2" crossorigin="anonymous"> <link rel="preload" href="/fonts/{font}.woff2" as="font" type="font/woff2" crossorigin="anonymous">

View File

@@ -1,3 +1,6 @@
@use "imports" as *;
/* /*
** Earth icon ** Earth icon
*/ */

View File

@@ -1,3 +1,6 @@
@use "../imports" as *;
.photo { .photo {
overflow: hidden; overflow: hidden;
background: $color-primary-tertiary20; background: $color-primary-tertiary20;

View File

@@ -1,3 +1,6 @@
@use "imports" as *;
html { html {
font: #{$base-font-size}/1.2 $font-sans; font: #{$base-font-size}/1.2 $font-sans;
font-weight: 400; font-weight: 400;

View File

@@ -1,3 +1,6 @@
@use "imports" as *;
/* /*
** Box shadows ** Box shadows
*/ */

View File

@@ -1,3 +1,5 @@
@use "imports" as *;
/* Fonts list /* Fonts list
========================================================================== */ ========================================================================== */
@include font-face("Garnett", "G-Light", 200); @include font-face("Garnett", "G-Light", 200);

View File

@@ -1,25 +1,22 @@
@charset "UTF-8"; @charset "UTF-8";
// Dependencies
@import "sanitize.css/sanitize";
// Tools // Tools
@import "tools/helpers"; @forward "tools/helpers";
// Base // Base
@import "variables-css"; @forward "variables-css";
@import "base"; @forward "base";
@import "fonts"; @forward "fonts";
@import "typography"; @forward "typography";
@import "effects";
// Layout // Layout
@import "layout/grid"; @forward "layout/grid";
@import "layout/modules"; @forward "layout/modules";
// Misc // Misc
@import "animations"; @forward "animations";
@forward "effects";
// Components (Atomic Design System) // Components (Atomic Design System)
// Atoms // Atoms
@import "atoms/photo"; @forward "atoms/photo";

View File

@@ -1,4 +1,3 @@
// Tools @forward "variables";
@import "variables"; @forward "tools/mixins";
@import "tools/mixins"; @forward "tools/functions";
@import "tools/functions";

View File

@@ -1,3 +1,6 @@
@use "../imports" as *;
/* /*
** Grid ** Grid
*/ */

View File

@@ -1,3 +1,6 @@
@use "../imports" as *;
.grid-modules { .grid-modules {
padding-bottom: 40px; padding-bottom: 40px;

View File

@@ -1,4 +1,7 @@
@use "sass:math"; @use "sass:math";
@use "sass:color";
@use "../variables" as *;
/* PX to REM /* PX to REM
========================================================================== */ ========================================================================== */
@@ -39,5 +42,5 @@
/* HEX color to RGB /* HEX color to RGB
========================================================================== */ ========================================================================== */
@function hexToRGB($color) { @function hexToRGB($color) {
@return red($color), green($color), blue($color); @return color.channel($color, "red", $space: rgb), color.channel($color, "green", $space: rgb), color.channel($color, "blue", $space: rgb);
} }

View File

@@ -1,3 +1,6 @@
@use "../imports" as *;
/* Classes /* Classes
========================================================================== */ ========================================================================== */
.clear { .clear {

View File

@@ -1,5 +1,7 @@
@use "sass:math"; @use "sass:math";
@use "sass:map"; @use "sass:map";
@use "../variables" as *;
// Hide text // Hide text
%hide-text { %hide-text {

View File

@@ -1,3 +1,6 @@
@use "imports" as *;
/* ========================================================================== /* ==========================================================================
TITLES TITLES
========================================================================== */ ========================================================================== */

View File

@@ -1,3 +1,6 @@
@use "imports" as *;
:root { :root {
// Sizes // Sizes
--container-width: #{$container-width}; --container-width: #{$container-width};

View File

@@ -1,18 +1,16 @@
import { sveltePreprocess } from 'svelte-preprocess'
import adapter from '@sveltejs/adapter-cloudflare'
import { fileURLToPath } from 'url' import { fileURLToPath } from 'url'
import { dirname } from 'path' import { dirname } from 'path'
import { sveltePreprocess } from 'svelte-preprocess'
import adapter from '@sveltejs/adapter-cloudflare'
const stylePath = `${dirname(fileURLToPath(import.meta.url))}/src/style` export const globalStyles = `@use "${dirname(fileURLToPath(import.meta.url))}/src/style/imports" as *;`
export const scssImports = `@use "${stylePath}/imports.scss" as *;`
/** @type {import('@sveltejs/kit').Config} */ /** @type {import('@sveltejs/kit').Config} */
const config = { const config = {
// Preprocessors docs: https://github.com/sveltejs/svelte-preprocess // Preprocessors docs: https://github.com/sveltejs/svelte-preprocess
preprocess: sveltePreprocess({ preprocess: sveltePreprocess({
scss: { scss: {
prependData: scssImports, prependData: globalStyles,
renderSync: true,
} }
}), }),

View File

@@ -1,15 +1,16 @@
import type { UserConfig } from 'vite' import { defineConfig } from 'vite'
import { sveltekit } from '@sveltejs/kit/vite' import { sveltekit } from '@sveltejs/kit/vite'
import { scssImports } from './svelte.config' import { globalStyles } from './svelte.config'
const config: UserConfig = { export default defineConfig({
plugins: [ plugins: [
sveltekit() sveltekit()
], ],
css: { css: {
preprocessorOptions: { preprocessorOptions: {
scss: { scss: {
additionalData: scssImports, additionalData: globalStyles,
api: 'modern',
} }
} }
}, },
@@ -18,6 +19,4 @@ const config: UserConfig = {
transformMixedEsModules: true, transformMixedEsModules: true,
} }
}, },
} })
export default config

BIN
bun.lockb

Binary file not shown.