In webpack entry file index.js I'm just importing 2 CSS files a.css and b.css but it is not working because of b.css does not see variable from a.css: WARNING in b.css... variable --textColor is undefined and used without a fallback
. How should I change webpack.config.js to get it work? I know I can directly import b.css in a.css but this is simple example, my project is much more complex with tens of CSS files and I do not want to change its content.
// webpack.config.js
var MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = (env, options) => {
return {
entry : 'index.js',
mode : 'development',
output : {
path : '/public',
},
plugins : [
new MiniCssExtractPlugin(),
],
module : {
rules : [
{
test : /\.css$/,
use : [
{
loader : MiniCssExtractPlugin.loader,
},
{
loader : 'css-loader',
},
{
loader : 'postcss-loader',
options : {
plugins: [
require('postcss-css-variables')(),
],
},
},
],
},
],
},
};
}
// index.js
import 'a.css';
import 'b.css';
// a.css
:root {
--textColor: red
}
// b.css
body {
color: var(--textColor);
}