I'm using the gem rails/webpack to build the assets, but I need build a dynamic SCSS according by a brand, like:
//admin.scss
@import 'variables-<%= 'brand-name' %>';
body {
background: $primary-color;
}
I have tried adding the loader:
{
test: /\.scss(\.erb)?/,
loader: 'sass-loader',
options: { importExtensions: ['.scss', '.scss.erb', '.css'] }
}
but that didn't work. Is there a way to do something like that?
Do this in a separate controller action:
layout.html.erb
<%= stylesheet_link_tag stylesheet_path() %>Stylesheet show controller action
You can then include the ERB variables in the template. Note that this will be put through the sass engine on every single load so you will want to cache this on production.
If you want to keep all your sass nicely organised into separate files just put your variables in one file to render as ERB and the rest just read in as text files.