I'm trying to pass some data to SCSS, based on entry point. I will have two themes and I have to know what theme Im currently bundling.
Webpack entry points :
webpack: {
entry: {
toyota: path.resolve(__dirname, '../entries/theme.toyota.js'),
lexus: path.resolve(__dirname, '../entries/theme.lexus.js'),
},
Then, I would like to recognise the entry point, and pass that as variable to SCSS:
test: /\.s?css$/,
exclude: /node_modules/,
use: [{
loader: 'sass-loader',
options: {
data: '$brand: "' + entryPointName +'";',
sourceMap: true
}
},
]
I already tried [name]
but no luck...
I could achieve that by running build again with different ENV variable, but i was hoping to achieve that with one task (for faster build time with watch).
Is there any way to achieve that?
Finally, solution is webpack layers...
webpack: {
entry: {
toyota: { import: path.resolve(__dirname, '../entries/theme.toyota.js'), layer: 'toyota' },
lexus: { import: path.resolve(__dirname, '../entries/theme.lexus.js'), layer: 'lexus' },
},
experiments: {
layers: true,
},
test: /\.s?css$/,
exclude: /node_modules/,
oneOf: [
{
issuerLayer: 'toyota',
use: [{
loader: 'sass-loader',
options: {
data: '$brand: "toyota";',
sourceMap: true
}
},
]
},
{
issuerLayer: 'lexus',
use: [{
loader: 'sass-loader',
options: {
data: '$brand: "lexus";',
sourceMap: true
}
},
]
},
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With