Skip to content

Using scss variables in theme.ts #28719

Answered by higginbg
higginbg asked this question in Help
Discussion options

You must be logged in to vote

I have not tried it. It looks like that is for webpack though, but my project is using vite.

I ended up writing this script to turn the scss variables into a js object. A little bit of a workaround but it works.

// Creates a js object from scss variables
// To get theme from a single source

import * as sass from 'sass';
import * as fs from 'fs';
import * as path from 'path';
import postcss from 'postcss';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const scssFilePath = path.resolve(__dirname, './variables.scss');

type VariableMap = Record<string, string>;

function extractVariablesFromScss(scssFile: 

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@higginbg
Comment options

Answer selected by higginbg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants