I have a Sage 10 theme (v10.6.0), and am using Bud (v6.12.2) as the build tool.
I am using bootstrap with sass, and have got it all working fine by following the guide in the sage docs.
My folder structure is like so:
- resources
- styles
app.scss
- blocks
- block-a.scss
- block-b.scss
- components
- component-a.scss
- component-b.scss
I’d like it to build and output like so:
- public
- css
app.css
- blocks
- block-a.css
- block-b.css
- components
- component-a.css
- component-b.css
The reason I’m doing this is so that I can enqueue the assets for my blocks and components only if they are being used on the page, while keeping everything a bit neater.
I’ve already come up with something that gets me part the way there: the below will grab all the scss files and js files from the styles/block folder and the scripts/blocks folder and will output them individually to the public/css and public/js folders, but I’d really like them to go into a ‘blocks’ subfolder within each of those css and js output directories. Then the same for the components folder (which I havent done yet, just want to get blocks working first).
my asset mapper (bud.config.js):
const blockFiles = {};
const processBlockFiles = async (filePattern, importPrefix) => {
const files = await app.glob(filePattern);
files.forEach((file) => {
const name = path.basename(file, path.extname(file));
const type = path.extname(file).slice(1);
blockFiles[name] = blockFiles[name] || { import: [], type };
blockFiles[name].import.push(`${importPrefix}/${name}`);
});
};
await processBlockFiles("resources/styles/blocks/*.scss", "@styles/blocks");
await processBlockFiles("resources/scripts/blocks/*.js", "@scripts/blocks");
how it’s used (bud.config.js):
app.entry({
app: ["@scripts/app", "@styles/app"],
editor: ["@scripts/editor", "@styles/editor"],
...blockFiles,
}).assets(["images"]);
I’ve read the great post below, but what I’m doing is a little different. I played around with some variants of it, but have gone in enough circles where I’m now reaching out
https://discourse.roots.io/t/bud-config-for-outputting-multiple-css-files-from-scss-for-acf-blocks/22498/6?u=izzyzzi
Any help would be greatly appreciated!