update to use new manual dependencies feature of transforms
This commit is contained in:
parent
c84cd56462
commit
1b4ff676ee
|
@ -8,39 +8,25 @@ const readText = filename =>
|
|||
export default function svelteCombiner({
|
||||
extensions = ['.html', '.svelte'],
|
||||
} = {}) {
|
||||
const externalFiles = new Set();
|
||||
return {
|
||||
load: id => {
|
||||
if (externalFiles.has(id)) {
|
||||
return '';
|
||||
}
|
||||
transform: (code, id) => {
|
||||
const extension = extensions.find(extension => id.endsWith(extension));
|
||||
if (extension) {
|
||||
const baseId = id.slice(0, -extension.length);
|
||||
const jsId = baseId + '.js';
|
||||
const cssId = baseId + '.css';
|
||||
externalFiles.add(jsId);
|
||||
externalFiles.add(cssId);
|
||||
return Promise.all([id, jsId, cssId].map(readText)).then(
|
||||
([html, js, css]) =>
|
||||
js
|
||||
? css
|
||||
? `${html}
|
||||
<script>
|
||||
${js}
|
||||
import ${JSON.stringify(jsId)}
|
||||
import ${JSON.stringify(cssId)}
|
||||
</script>
|
||||
<style>
|
||||
${css}
|
||||
</style>`
|
||||
: `${html}
|
||||
<script>
|
||||
${js}
|
||||
import ${JSON.stringify(jsId)}
|
||||
</script>`
|
||||
: html
|
||||
);
|
||||
return Promise.all([jsId, cssId].map(readText)).then(([js, css]) => {
|
||||
const dependencies = [];
|
||||
if (js) {
|
||||
dependencies.push(jsId);
|
||||
code += `\n<script>\n${js}\n</script>\n`;
|
||||
}
|
||||
if (css) {
|
||||
dependencies.push(cssId);
|
||||
code += `\n<style>\n${css}\n</style>\n`;
|
||||
}
|
||||
return { code, dependencies };
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue