Closed MatthewAry closed 5 years ago
Also having this issue - we can run and serve, but all unit testing fails with sass-loader errors once a vuetify component is added to the HelloWorld.vue component:
So will this code [...]
The paths need to be changed to match what you have in your project, it's just an example.
@ZarekParker not sure about mocha, but jest needs
transform: {
'\\.s[ac]ss$': 'jest-css-modules'
}
I am also having this issue with Vuetify 2.0.0. I had to install an older version of Vuetify.
+1
So I think I got this working in your test repo in two different ways depending on if you want to use scss
or sass
in the SFC.
sass
Note the absence of a ;
on the import statement
// vue.config.js
css: {
loaderOptions: {
sass: {
data: '@import "~@/sass/main.scss"',
implementation: require("sass"),
fiber: require("fibers")
}
},
sourceMap: true
}
You can then use sass
style in SFC and use variables
<style lang="sass">
.test
color: map-get($red, 'base')
</style>
scss
Note the config modification where we make sure there is a ;
present when using scss
// vue.config.js
css: {
loaderOptions: {
sass: {
data: '@import "~@/sass/main.scss"',
implementation: require("sass"),
fiber: require("fibers")
}
},
sourceMap: true
},
chainWebpack: config => {
["vue-modules", "vue", "normal-modules", "normal"].forEach((match) => {
config.module.rule('scss').oneOf(match).use('sass-loader')
.tap(opt => Object.assign(opt, { data: `@import '~@/sass/main.scss';` }))
});
}
You can then use scss
in SFC
<style lang="scss">
.test {
color: map-get($red, "base");
}
</style>
@nekosaur that did not have any effect on my project
Okay, so my issue was that the Alias being used in the import path was not mapping to my src folder. I fixed that, and now the issue I was having resolved.
As for the docs on using SASS variables, I think it need significantly more details added to it as without it, there will probably be more issues like these.
I'm leaving this open for the other affected user.
@ZarekParker Perhaps try this
In package.json
update unit:test
script with --require ./tests/noop.js
Add tests/noop.js
file with content
function noop () {
return null
}
require.extensions['.css'] = noop
require.extensions['.less'] = noop
require.extensions['.scss'] = noop
require.extensions['.sass'] = noop
Since original issue has been solved, and documentation has been updated, I am closing this issue.
It seems that the documentation that was added in response to this issue has been removed since Vuetify 2.2. What is the recommended way to create global styles that may even override vuetify styles with this update?
Versions and Environment
Vuetify: 2.0.0 Vue: 2.6.10 Browsers: Chrome 75.0.3770.142 OS: Mac OS 10.14.5
Steps to reproduce
Expected Behavior
No errors
Actual Behavior
Errors relating to using sass variables on single-file components.
Reproduction Link
https://github.com/MatthewAry/vuetify-sass-variables
Other comments
Some background
I followed the directions https://vuetifyjs.com/en/customization/sass-variables and did some experiments. Attempts to try to use Single File components with styles with the instructions to override vuetify SASS variables fails. https://vuetifyjs.com/en/customization/sass-variables#single-file-components attempts to address this problem but it does not seem to work.
This code:
will break the build process.
So will this code:
Note that the
Object.assign(opt, { data: `@import '~@/sass/main.sass'` })
and thedata: `@import "~@/sass/main.scss";`,
paths are different? Trying to make them match also does not fix the problem.Related to: https://github.com/vuejs/vue-cli/issues/4116 Related to: #7795 Documentation Reference: https://vuetifyjs.com/en/customization/sass-variables