I am trying to add a variable to my scss
files, referenced to .env
variable. To achieve this, I've read a few tutorials, and I found this. I need to add this configuration to my next.config.js
const withImages = require('next-images');
module.exports = withImages({
webpack(config, options) {
config.module.rules.push({
test: /\.s[ac]ss$/i,
use: [
{
loader: "css-loader",
options: {
importLoaders: 2,
modules: {
compileType: 'module'
}
}
},
{
loader: 'sass-loader',
options: {
additionalData: `$cdnURL: '${process.env.NEXT_PUBLIC_CDN_URL}';`
}
}
]
})
return config
}
})
As you can see, I remove the style-loader
, because I am getting this error. So when I remove this, I am able to proceed. I was able to add the environment variable; however, I am overriding the default scss configuration
of next
. So whenever I am trying to build my project, I got this warning
:
Warning: Built-in CSS support is being disabled due to custom CSS configuration being detected.
See here for more info: https://err.sh/next.js/built-in-css-disabled
The application is running, but the scss
was not bundled as a module I believe.
So is there anyway wherein I can add my environment variable
to scss
without overriding next.js
configuration as a whole?