0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00
astro/snowpack-plugin.cjs
Drew Powers 04a443a888
Add React component SSR (#28)
* Add React component SSR

* Add React component SSR
2021-03-25 16:59:38 -06:00

26 lines
800 B
JavaScript

const { readFile } = require('fs').promises;
// Snowpack plugins must be CommonJS :(
const transformPromise = import('./lib/compiler/index.js');
module.exports = function (snowpackConfig, { resolve, extensions } = {}) {
return {
name: 'snowpack-astro',
knownEntrypoints: ['deepmerge'],
resolve: {
input: ['.astro', '.md'],
output: ['.js'],
},
async load({ filePath }) {
const { compileComponent } = await transformPromise;
const projectRoot = snowpackConfig.root;
const contents = await readFile(filePath, 'utf-8');
const compileOptions = {
resolve,
extensions,
};
const result = await compileComponent(contents, { compileOptions, filename: filePath, projectRoot });
return result.contents;
},
};
};