-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Global SCSS Imports #832
Comments
It's useful |
Question if i want to prepend my mixin globaly and refer to it in my components Style tags. how i can do that ? vite.config.js
resultbut when i try to @include my mixin in my App.vue i get this error my package.json
|
I have also encountered this problem and am looking for a solution, but have not found a useful solution. |
This is working fine for me. My config looks like this: import { SharedConfig } from 'vite'
const config: SharedConfig = {
cssPreprocessOptions: {
scss: {
additionalData: '$primary: red;'
}
}
}
export default config The biggest issue right now is #650, as there is no good way of importing files. For example the following wouldn't work: I'm using SCSS btw, but the same solution should work for plain CSS or anything else. |
這個對我有用。 import path from "path";
const pathSrc = path.resolve(__dirname, "./src");
export default {
// ...
css: {
preprocessorOptions: {
scss: { additionalData: `@import "${pathSrc}/scss/variables";` },
},
},
}; |
It's working perfectly for me export default {
css: {
preprocessorOptions: {
scss: {
// example : additionalData: `@import "./src/design/styles/variables";`
// dont need include file extend .scss
additionalData: `@import "./src/path-to-scss-variables";`
},
},
},
}; |
- reference: vitejs/vite#832
global stylus imports not work, less and scss works preprocessorOptions: { |
Stylus doesn't work either |
hi, there is a simple plugin demo for import type { Plugin } from 'vite'
import path from 'path'
export function importStylus(): Plugin {
return {
name: 'vite-stylus-import-plugin',
async transform(code, id) {
if (/.stylus$/g.test(id)) {
return {
code: `
@import "${path.resolve(__dirname, pathToStylFile)}"
${code}
`,
map: null,
}
}
return null
}
}
} use in import { importStylus } from './vite-stylus-import-plugin.ts'
//***
plugins: [
{
...importStylus(),
enforce: 'pre',
},
] |
Greetings, For the record, I came across looking deeper into the Vite source code and I have a solution for stylus which works using
will result in: if your stylus file are named
otherwise, if you named them
In other words, you can use Conclusion (TLDR)This config works:
|
@qnp Good job bro! It's working fine for me.
|
I don't think it's working for sass imports from inside node_modules: I want to define variables that vuetify can then use, but the variables are only defined in my own stylesheets, not in vuetifty's imports. For example vuetify's
which imports:
which contains default values: $card-actions-padding: 8px !default;
$card-adjacent-sibling-text-padding-top: 0 !default;
$card-border-radius: $border-radius-root !default;
$card-btn-margin-x: 8px !default;
$card-btn-padding: 0 8px !default;
// ... But they aren't overwritten even with |
@coyotte508 if you are on 2.3.2 could you try upgrading to 2.3.3? |
I was on 2.3.1, still the same issue after upgrading. |
@Niputi I created a sample repo to reproduce the issue: https://github.com/coyotte508/vite-vuetify-scss |
@coyotte508 might be a good idea to open a new issue with that reproduction |
In case you landed here and code discussed above doesn't work, https://vitejs.dev/config/#css-modules updated code:
|
This issue gets locked because it has been closed for more than 14 days. |
Is your feature request related to a problem? Please describe.
I have a scss file with variables I would like to use throughout my app without importing it in every
<style>
block.Describe the solution you'd like
A configuration option in vite.config.js which directly or indirectly would allow users to prepend sass as is possible in vue.config.js using
prependData
oradditionalData
depending on your sass-loader version.Describe alternatives you've considered
I noticed that vuejs/core#2126 was cited in reference to closing #520, a similar request, but I'm not sure how that's applicable to vite given that it doesn't use webpack and as far as I can tell doesn't use sass-loader.
Additional context
Another separate but related problem is that
@import
only seems to be working with relative paths; e.g. with the default project setup@import ./src/whatever.scss
works fine but@import /src/whatever.scss
does not. Supposing that is in fact the case and something likeadditionalData
where possible to use in vite then relative paths would break for components in nested directories. Implementing #650 to resolve aliases in scss files might work though.The text was updated successfully, but these errors were encountered: