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

28 lines
834 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/compiler/index.js');
2021-03-15 12:22:05 -05:00
module.exports = function (snowpackConfig, { resolve, extensions, astroConfig } = {}) {
2021-03-15 12:22:05 -05:00
return {
name: 'snowpack-astro',
knownEntrypoints: ['deepmerge'],
2021-03-15 12:22:05 -05:00
resolve: {
input: ['.astro', '.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 = {
astroConfig,
resolve,
extensions,
};
const result = await compileComponent(contents, { compileOptions, filename: filePath, projectRoot });
2021-03-15 12:22:05 -05:00
return result.contents;
},
};
};