astro/snowpack-plugin.cjs
Matthew Phillips 3c24faa8ca
hmx ☞ astro (#22)
This changes all hmx files to astro files and updates all code to not reference hmx any more.
2021-03-24 11:45:38 -04:00

26 lines
795 B
JavaScript

const { readFile } = require('fs').promises;
// Snowpack plugins must be CommonJS :(
const transformPromise = import('./lib/transform2.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;
},
};
};