Sass additionalData and @use #6361
-
Hello, it is possible set
Any ideas? Thanks |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
An easy but inefficient way would be to just chuck the @use into additionalData, like this: scss: { Otherwise you could just manually import only what you need in each file. |
Beta Was this translation helpful? Give feedback.
-
In each file, I would like to have only what I import and what I use (@use). So this is not the right way to go. The current solution is that additionalData is a function and I insert the content after the last @use via the content parameter. But I would probably expect this from the additionalData behavior itself, otherwise it's not very useful. |
Beta Was this translation helpful? Give feedback.
-
@pepa-linha thanks for the hint. This works great! Here the code I ended up using to do so: const imports = `@import 'imports';`
const additionalData = content => {
// If there are @use statements, insert the import after the last one,
// otherwise insert it before all content.
const match = content.match(/@use '[^']+';/g)
if (match) {
const last = match[match.length - 1]
return content.replace(last, `${last}\n${imports}`)
} else {
return `${imports}\n${content}`
}
} |
Beta Was this translation helpful? Give feedback.
In each file, I would like to have only what I import and what I use (@use).
So this is not the right way to go. The current solution is that additionalData is a function and I insert the content after the last @use via the content parameter. But I would probably expect this from the additionalData behavior itself, otherwise it's not very useful.