I’m trying to improve the Svelte compiler plugin zodern:melte
(cc @zodern ) by also including CSS output in the Meteor build (currently it includes only CSS bundled in JS).
Implementing compileOneFileLater
seems tricky.
Here it is in it’s current state:
compileOneFileLater(file, getResult) {
// Search for top-level head and body tags. If at least one of these tags
// exists, the file is not processed with the Svelte compiler. Instead, the
// inner HTML of the tags is added to the respective section in the HTML
// output generated by Meteor.
const sections = this.getHtmlSections(file);
if (sections) {
sections.forEach(section => file.addHtml(section));
} else {
file.addJavaScript({
path: file.getPathInPackage()
}, async () => {
return await getResult();
});
}
}
The problem is, I have to get both JS and CSS added.
I tried looking for some guidance from @akryum 's Vue-package, but it doesn’t implement compileOneFileLater
.
It seems I can get it to work if I include both JS and CSS in the return value of compileOneFile
and add the CSS from within the async callback in file.addJavaScript
:
file.addJavaScript({
path: file.getPathInPackage()
}, async () => {
const { js, css } = await getResult();
file.addStylesheet(css);
return js;
});
…but there are, with absolute certainty, things I haven’t yet accounted for, as I’m once again re-learning how compiler plugins (and zodern:melte
) work
Any ideas?