summaryrefslogtreecommitdiff
path: root/snowpack-plugin.cjs
diff options
context:
space:
mode:
Diffstat (limited to 'snowpack-plugin.cjs')
-rw-r--r--snowpack-plugin.cjs50
1 files changed, 1 insertions, 49 deletions
diff --git a/snowpack-plugin.cjs b/snowpack-plugin.cjs
index 82be28b13..969b6075e 100644
--- a/snowpack-plugin.cjs
+++ b/snowpack-plugin.cjs
@@ -12,58 +12,10 @@ module.exports = function (snowpackConfig, { resolve } = {}) {
output: ['.js'],
},
async load({ filePath }) {
- const { compilePage, compileComponent } = await transformPromise;
+ const { compileComponent } = await transformPromise;
const projectRoot = snowpackConfig.root;
const contents = await readFile(filePath, 'utf-8');
-
- if (!filePath.includes('/pages/') && !filePath.includes('/layouts/')) {
const result = await compileComponent(contents, { compileOptions: { resolve }, filename: filePath, projectRoot });
- return result.contents;
- }
- const result = await compilePage(contents, {
- compileOptions: { resolve },
- filename: filePath,
- projectRoot,
- });
-
- try {
- return /* js */ `
- ${result.contents}
-
- export default async (childDatas, childRenderFns) => {
- // Kind of hacky, can clean up if this works
- const renderHmx = {setup, head, body};
- const merge = (await import('deepmerge')).default;
- const content = childDatas && childDatas[0].content;
- const _data = await renderHmx.setup({content});
- if (_data.layout) {
- const renderLayout = (await import('/_hmx/layouts/' + _data.layout.replace(/.*layouts\\//, "").replace(/\.hmx$/, '.js'))).default;
- return renderLayout(
- [...(childDatas || []), _data],
- [...(childRenderFns || []), renderHmx]
- );
- }
- const data = merge.all([_data, ...(childDatas || [])]);
- let headResult;
- let bodyResult;
- for (const renderFn of (childRenderFns || [])) {
- let headAndBody = await Promise.all([
- renderFn.head(data, headResult),
- renderFn.body(data, bodyResult)
- ]);
- headResult = headAndBody[0];
- bodyResult = headAndBody[1];
- }
- return h(Fragment, null, [
- renderHmx.head(data, headResult, true),
- renderHmx.body(data, bodyResult, true),
- ]);
- };
- `;
- } catch (err) {
- console.error(err);
- }
-
return result.contents;
},
};