Lately, I have been dedicating time to solving this particular issue. After exploring the i18n example config on GitHub, I discovered a method that showcases how it is achievable. Essentially, the webpack configuration can be structured as an array, allowing for operations like the following:
import webpack from 'webpack';
export default [
{
entry: {
'brand-1': ['path/to/vars-1.scss', 'path/to/my.scss'],
}
// ...
},
{
entry: {
'brand-2': ['path/to/vars-2.scss', 'path/to/my.scss'],
}
// ...
},
];
In practice, you may choose to generate this list programmatically, but I opted to write it out explicitly for better comprehension. Due to our dynamic SCSS variables, I conceived a script responsible for crafting the webpack configuration and subsequently injecting the variables utilizing the sassLoader.data feature.
To streamline the process, incorporating webpack-merge is advisable to compartmentalize the configurations effectively.
const common = {
module: {
loaders: {
// ...
},
},
};
export default BRANDS.map((brand) => (
merge(
common,
{
entry: {
[brand.name]: [brand.variableFile, 'path/to/my.scss'],
},
// Additional customization if needed.
plugins: [
webpack.DefinePlugin({
BRAND_NAME: brand.name,
}),
],
},
)
));
Personally, I employ the ExtractTextPlugin approach by instantiating one for each individual brand. While uncertain of its correctness, I continue to explore how it intertwines with the CommonChunksPlugin for potential solutions.
As the journey progresses, I remain optimistic in unlocking further insights and resolving any outstanding concerns along the way.