feat: generate theme.json during dev mode using in-memory CSS#15
feat: generate theme.json during dev mode using in-memory CSS#15eavonius wants to merge 2 commits intoroots:mainfrom
Conversation
- Enables writing theme.json to disk when running Vite in dev mode - Extracts CSS from the in-memory transform hook instead of relying on output files - Writes to public/build/assets for compatibility with Sage - Still generates theme.json during build - Adds support for hashed CSS filenames when resolving in build
…ile to be changed).
|
A complication I ran into, is that as soon as $dependencies = json_decode(Vite::content('editor.deps.json'));It finds the build directory there - and thinks this is a prod build. This errors out since it can't find the editor deps. I didn't realize this was a problem until I tried to hop into the admin side of the site once the "built" theme.json exists. So I'm not sure what to do next. |
|
I was able to get this to work. It would require users add a line to add_filter('admin_head', function () {
if (! get_current_screen()?->is_block_editor()) {
return;
}
if (defined("WP_ENV") && WP_ENV !== 'development') {
$dependencies = json_decode(Vite::content('editor.deps.json'));
foreach ($dependencies as $dependency) {
if (! wp_script_is($dependency)) {
wp_enqueue_script($dependency);
}
}
}
echo Vite::withEntryPoints([
'resources/js/editor.js',
])->toHtml();
}); |
|
Thanks for putting this together and for working through the We've been working on an alternative implementation that takes a different approach: no new dependencies, no hardcoded paths, debounced atomic writes, and startup generation via Thanks again |
This PR adds support for generating
theme.jsonduring development.theme.jsonduringvite dev.resources/cssduring dev andpublic/buildduring a build.app-*.css) during a build.Tested with: