I’ve inherited a few sites that don’t have a complete theme rebuild in the budget so i’m trying to make a drop-in custom plugin that integrates bud for tooling. I’ve tried integrating based off of the example here: https://github.com/roots/bud/blob/4c845ed204b91f445027c5eeee659b3124c93b6a/examples/wordpress-theme/
I couldn’t get the example in functions.php to work (after composer install) and ended up writing the following which is working
add_action('wp_enqueue_scripts', 'bud_enqueue_assets', 999);
add_action('admin_enqueue_scripts', 'bud_enqueue_assets', 999);
function bud_enqueue_assets()
{
$plugin_path = plugin_dir_path(__FILE__) . '/';
$manifestPath = $plugin_path . 'dist/entrypoints.json';
$manifestJson = file_get_contents($manifestPath);
$manifest = json_decode($manifestJson, true);
$bundleName = 'app';
if (isset($manifest[$bundleName])) {
$bundle = $manifest[$bundleName];
if (isset($bundle['js'])) {
$jsFiles = $bundle['js'];
foreach ($jsFiles as $jsFile) {
$jsFileUrl = plugins_url('dist/' . $jsFile, __FILE__);
wp_enqueue_script(
basename($jsFile),
$jsFileUrl,
[],
null,
true
);
}
}
if (isset($bundle['css'])) {
$cssFiles = $bundle['css'];
foreach ($cssFiles as $cssFile) {
$cssFileUrl = plugins_url('dist/' . $cssFile, __FILE__);
wp_enqueue_style(
basename($cssFile),
$cssFileUrl,
[],
null
);
}
}
}
}
bud build production
is working as expected and correctly displaying compiled js/css on the frontend
bud build development
though is only rendering JS… I can see the compiled CSS is injected into app.js but it is not rendered on the frontend.
I used npx create-bud-app and am using the following:
"@roots/bud": "^6.16.1",
"@roots/bud-babel": "^6.16.1",
"@roots/bud-eslint": "^6.16.1",
"@roots/bud-postcss": "^6.16.1",
"@roots/bud-preset-wordpress": "^6.16.1",
"@roots/bud-prettier": "^6.16.1",
"@roots/bud-sass": "^6.16.1",
"@roots/bud-stylelint": "^6.16.1",
"@roots/eslint-config": "^6.16.1"
// bud.config.ts
import type {Bud} from '@roots/bud';
/**
* bud.js configuration
*/
export default async (bud: Bud) => {
bud
.hash(true)
.entry('app', ['index.js', 'index.scss'])
.watch('app')
.proxy('https://valet-experiment.test', (searches) => [
...searches,
['0.0.0.0:3000', '10.0.1.205:3000'], // Replace with correct address
])
.serve('http://localhost:3000');
bud.stylelint
.setFailOnError(bud.isProduction)
.setFailOnWarning(false)
.setFix(true);
//
};
Not sure where I’m going wrong… any guidance would be greatly appreciated.
Thanks in advance