question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Does not work scss variables when I change the directory path css in quasar.config.js

See original GitHub issue

What happened?

quasar.variables.scss(src/app/styles):

$app-bg-color: #f2f8ff;

Global variable in component:

<template>
  <div class="c"></div>
</template>

<style lang="scss">
.c {
  background: $app-bg-color;
}
</style>

But, I have error:

Syntax Error: SassError: Undefined variable.

It only works if you import a file with variables wherever variables are used.

Quasar config:

{
  css: [
    '../app/styles/app.scss',
    '../app/styles/width.scss',
  ],
}

// or

{
  css: [
    '../app/css/app.scss',
    '../app/css/width.scss',
  ],
}

What did you expect to happen?

I use variables as before

Reproduction URL

https://stackblitz.com/edit/quasarframework-webpack-nvwe18?file=src/app/css/quasar.variables.scss

How to reproduce?

Follow the link above

Flavour

Quasar CLI with Webpack (@quasar/cli | @quasar/app-webpack)

Areas

Quasar CLI Commands/Configuration (@quasar/cli | @quasar/app-webpack | @quasar/app-vite)

Platforms/Browsers

Chrome

Quasar info output

No response

Relevant log output

No response

Additional context

No response

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rstoenescucommented, Oct 3, 2022

Hi,

quasar.variables.scss needs to be in its original place (src/css) otherwise it’s like you’re not using this feature.

0reactions
doox911commented, Oct 4, 2022

Hi,

quasar.variables.scss needs to be in its original place (src/css) otherwise it’s like you’re not using this feature.

Can I add a parameter to the configuration?

https://github.com/quasarframework/quasar/blob/dev/app-webpack/lib/webpack/create-chain.js

  injectStyleRules(chain, {
    isServerBuild: configName === webpackNames.ssr.serverSide,
    rtl: cfg.build.rtl,
    sourceMap: cfg.build.sourceMap,
    extract: cfg.build.extractCSS,
    minify: cfg.build.minify,
    stylusLoaderOptions: cfg.build.stylusLoaderOptions,
    sassLoaderOptions: cfg.build.sassLoaderOptions,
    scssLoaderOptions: cfg.build.scssLoaderOptions,
    lessLoaderOptions: cfg.build.lessLoaderOptions
  })

Add in cfg.build.sassLoaderOptions and cfg.build.scssLoaderOptions new property - CSS_VARIABLES_PATH from quasar.config.js.

Then we could throw them in https://github.com/quasarframework/quasar/blob/dev/app-webpack/lib/helpers/css-variables.js through https://github.com/quasarframework/quasar/blob/dev/app-webpack/lib/webpack/inject.style-rules.js.

  appFile(CSS_VARIABLES_PATH):  => ({
    scss: fs.existsSync(appPaths.resolve.src(`${CSS_VARIABLES_PATH}/quasar.variables.scss`)),
    sass: fs.existsSync(appPaths.resolve.src(`${CSS_VARIABLES_PATH}/quasar.variables.sass`))
  }),

This is an example. If you think about it, it can be done more elegantly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Sass/SCSS Variables - Quasar Framework
Quasar CLI detects if the file contains at least one '$' character, and if so, it automatically imports the Quasar Sass/SCSS variables. ......
Read more >
Quasar variables are undefined if use @use instead ... - GitHub
Is there any way to include them with @use and access quasar variables or do we have to use @import?
Read more >
Storybook Global Scss variables - Stack Overflow
For me, creating a webpack.config.js file in the .storybook folder with the below configuration solved my problem: module.exports = (storybookBaseConfig ...
Read more >
Public Path - webpack
The publicPath configuration option can be quite useful in a variety of ... To approach this problem you can easily use a good...
Read more >
global css cannot be imported from files other than your ...
js CSS loader (see here) instead of legacy @zeit/next-sass . Replace @zeit/next-sass package with sass . Remove next.config.js . Or do not ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found