Use @roots/vite-plugin (#3231)

Co-authored-by: Brandon <brandon@tendency.me>
This commit is contained in:
Ben Word
2025-02-22 15:13:42 -05:00
committed by GitHub
parent 8cc24bab95
commit 2f2d67fb7f
7 changed files with 264 additions and 792 deletions

View File

@@ -1,45 +1,5 @@
import domReady from '@wordpress/dom-ready';
domReady(() => {
// DOM has been loaded
//
});
if (import.meta.hot) {
import.meta.hot.on('vite:beforeUpdate', (payload) => {
const cssUpdates = payload.updates.filter(update => update.type === 'css-update');
if (cssUpdates.length > 0) {
const update = cssUpdates[0];
// Find the iframe
const editorIframe = document.querySelector('iframe[name="editor-canvas"]');
if (!editorIframe?.contentDocument) {
window.location.reload();
return;
}
// Find the existing style tag in the iframe
const styles = editorIframe.contentDocument.getElementsByTagName('style');
let editorStyle = null;
for (const style of styles) {
if (style.textContent.includes('editor.css')) {
editorStyle = style;
break;
}
}
if (!editorStyle) {
window.location.reload();
return;
}
// Update the style content with new import and cache-busting timestamp
const timestamp = Date.now();
editorStyle.textContent = `@import url('${window.__vite_client_url}${update.path}?t=${timestamp}')`;
return;
}
// For non-CSS updates, reload
window.location.reload();
});
}