mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
854d0feb34
* Add support for React components. This adds support for react components via a new `extensions` config in astro.config.mjs. In the future we can extend this to do things like look at the import statements, as Snowpack does. * Fix the tests
26 lines
791 B
JavaScript
26 lines
791 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-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 compileOptions = {
|
|
resolve,
|
|
extensions
|
|
};
|
|
const result = await compileComponent(contents, { compileOptions, filename: filePath, projectRoot });
|
|
return result.contents;
|
|
},
|
|
};
|
|
};
|