Skip to content

Commit 3e199a4

Browse files
committed
Add global scss vars
1 parent c251d91 commit 3e199a4

File tree

7 files changed

+40
-25
lines changed

7 files changed

+40
-25
lines changed

errorpages/pages/_error/[id].html.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ useSeoMeta({ title: `${errorpage?.name} - Chirality` });
1818
</template>
1919

2020
<style lang="scss">
21-
@use "@workspace/ui-lib/scss/colors.scss";
22-
2321
html {
2422
font-family: Arial, Helvetica, sans-serif;
2523
background-color: colors.$background;

home/components/TileContainer.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ defineProps<{ tiles: Tile[]; }>();
1616
</template>
1717

1818
<style lang="scss" scoped>
19-
@use "@workspace/ui-lib/scss/breakpoints.scss";
20-
2119
section {
2220
padding: 1em;
2321
display: flex;

ui-lib/components/AppHeader.vue

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@ defineProps<{
3232
</template>
3333

3434
<style lang="scss" scoped>
35-
@use "../scss/colors.scss";
36-
@use "../scss/breakpoints.scss";
37-
3835
header {
3936
position: sticky;
4037
top: 0;

ui-lib/index.ts

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { defineNuxtModule, createResolver, addComponentsDir, installModule } from "@nuxt/kit";
22
import defu from "defu";
3+
import type { NuxtOptions, Nuxt } from "@nuxt/schema";
34

45
export interface Config {
56
appName: string,
@@ -18,29 +19,56 @@ const defaults: Config = {
1819
logoutUrl: "https://auth.chirality.de",
1920
};
2021

22+
const scssModules = [
23+
"./scss/colors.scss",
24+
"./scss/breakpoints.scss"
25+
];
26+
27+
const resolver = createResolver(import.meta.url);
28+
2129
export default defineNuxtModule({
2230
meta: { name: "ui-lib" },
2331
defaults,
2432

2533
async setup(_, nuxt) {
26-
const resolver = createResolver(import.meta.url);
27-
2834
installModule("@nuxt/eslint");
2935
installModule("@nuxt/fonts");
3036
installModule("@nuxt/icon");
3137

3238
nuxt.options.runtimeConfig.public = defu(nuxt.options.runtimeConfig.public, defaults);
33-
nuxt.options.css.push(resolver.resolve("./scss/global.scss"));
3439

35-
nuxt.hook("nitro:config", async (nitroConfig) => {
36-
(nitroConfig.publicAssets ??= []).push({
37-
dir: resolver.resolve("./public"),
38-
maxAge: 60 * 60 * 24 * 365, // 1 year
39-
});
40-
});
40+
registerCss(nuxt.options);
41+
registerAssets(nuxt);
4142

42-
await addComponentsDir({
43-
path: resolver.resolve("./components"),
44-
});
43+
await registerComponents();
4544
},
4645
});
46+
47+
function registerComponents() {
48+
return addComponentsDir({
49+
path: resolver.resolve("./components"),
50+
});
51+
}
52+
53+
function registerAssets(nuxt: Nuxt) {
54+
nuxt.hook("nitro:config", async (nitroConfig) => {
55+
(nitroConfig.publicAssets ??= []).push({
56+
dir: resolver.resolve("./public"),
57+
maxAge: 60 * 60 * 24 * 365,
58+
});
59+
});
60+
}
61+
62+
function registerCss(options: NuxtOptions) {
63+
// global scss variables
64+
const scssImports = scssModules
65+
.map(m => resolver.resolve(m))
66+
.map(m => `@use "${m}";`)
67+
.join("");
68+
69+
options.vite = defu(options.vite, { css: { preprocessorOptions: { scss: { additionalData: scssImports, } } } });
70+
71+
// global styles
72+
options.css.push(resolver.resolve("./scss/global.scss"));
73+
}
74+

ui-lib/scss/global.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
@use "./colors.scss";
2-
31
html {
42
box-sizing: border-box;
53
}

web/components/SocialLinks.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ const { matrixUrl, githubUrl, printablesUrl } = useRuntimeConfig().public;
2020
</template>
2121

2222
<style lang="scss">
23-
@use "@workspace/ui-lib/scss/colors.scss";
24-
2523
.links {
2624
font-size: 2.5em;
2725
margin: 2em auto 0 auto;

web/pages/index.vue

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ useSeoMeta({ description: "Nothing to see here (yet)" });
1818
</template>
1919

2020
<style lang="scss">
21-
@use "@workspace/ui-lib/scss/breakpoints.scss";
22-
2321
.placeholder {
2422
width: 32em;
2523
height: 24em;

0 commit comments

Comments
 (0)