additionalData option does not work
See original GitHub issue- Operating System: macOS 11.2.3
- Node Version: v14.15.3
- NPM Version: 7.6.3
- webpack Version: 5.24.4
- sass-loader Version: 11.0.1
Expected Behavior
Adding an import line to a specific .scss file using the additionalData option
Actual Behavior
The line is not added, the file remains exactly the same as it was
Code
Trying to add imports with just a line
// webpack.config.js
module: {
rules: [{
test: /\.scss$/,
include: [PATHS.global],
use: ["style-loader", "css-loader", "sass-loader"]
}, {
test: /\.scss$/,
include: [PATHS.variables],
use:
["style-loader", "css-loader", {
loader: "sass-loader",
options: {
additionalData: `@import "src/styles/themes/${theme}Theme.scss";`
}
}]
}, {
test: /\.scss$/,
exclude: [/node_modules/, PATHS.global, PATHS.variables],
use: [
"style-loader", {
loader: "css-loader",
options: {
import: true,
sourceMap: true,
modules: {
mode: "local",
localIdentName: "[path][name]__[local]--[hash]",
exportLocalsConvention: "camelCase"
}
}
}, {
loader: "postcss-loader",
options: {
sourceMap: true,
postcssOptions: {
config: path.resolve(__dirname, "postcss.config.js")
}
}
}, {
loader: "sass-loader",
options: {
sourceMap: true
}
}
]
},
...
]
}
Trying to add imports using a function
// webpack.config.js
module: {
...
{
test: /\.scss$/,
include: [PATHS.variables],
use:
["style-loader", "css-loader", {
loader: "sass-loader",
options: {
additionalData: (content: string) => `@import "src/styles/themes/${theme}Theme.scss";\n${content}`
}
}]
}
...
]
}
The file where you want to add the import
// variables.scss
$header-height: 50px;
$ext-line-height: 45px;
$editor-tabs-height: 30px;
$wizard-action-height: 65px;
$app-height: calc(100vh - #{$header-height});
$content-height: calc(#{$app-height} - #{2*$ext-line-height});
$wizard-height: $app-height;
$wizard-content-height: calc(#{$wizard-height} - #{$wizard-action-height});
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
After adding additionalData I got module build failed error #880
Hey I used Vue CLI and change it webpack configs and a sass file as an additionalData. but after add this option my...
Read more >storybook vue sass additionalData not working - Stack Overflow
We have a central and shared storybook library for common components that was working perfectly, but now we share the variables it fails....
Read more >sass-loader - webpack - JS.ORG
Node Sass does not work with Yarn PnP feature and doesn't support @use rule. Warning ... Options. implementation; sassOptions; sourceMap; additionalData ...
Read more >Selecting data center regions for meetings/webinars
Data center regions selections apply only for meeting and webinar data in transit. The selections do not impact the location of data at...
Read more >Using Pre-Processors - Vue Loader - Vue.js
sass-loader also supports a additionalData option which allows you to share common variables among all processed files without having to explicit import ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Got it, thanks a lot for the clarification
Yes,
node-sass/dart-sasslimitation