0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00
astro/snowpack-plugin.cjs
2021-03-21 00:44:42 -07:00

22 lines
718 B
JavaScript

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