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

27 lines
791 B
JavaScript
Raw Normal View History

const { readFile } = require('fs').promises;
2021-03-15 12:22:05 -05:00
// Snowpack plugins must be CommonJS :(
const transformPromise = import('./lib/transform2.js');
2021-03-15 12:22:05 -05:00
module.exports = function (snowpackConfig, { resolve, extensions } = {}) {
2021-03-15 12:22:05 -05:00
return {
name: 'snowpack-hmx',
knownEntrypoints: ['deepmerge'],
2021-03-15 12:22:05 -05:00
resolve: {
input: ['.hmx', '.md'],
output: ['.js'],
2021-03-15 12:22:05 -05:00
},
async load({ filePath }) {
2021-03-21 02:44:42 -05:00
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 });
2021-03-15 12:22:05 -05:00
return result.contents;
},
};
};