2021-03-19 20:55:06 +00:00
|
|
|
const { readFile } = require('fs').promises;
|
2021-03-15 17:22:05 +00:00
|
|
|
|
|
|
|
// Snowpack plugins must be CommonJS :(
|
2021-03-19 20:55:06 +00:00
|
|
|
const transformPromise = import('./lib/transform2.js');
|
2021-03-15 17:22:05 +00:00
|
|
|
|
|
|
|
module.exports = function (snowpackConfig, { resolve } = {}) {
|
|
|
|
return {
|
2021-03-19 20:55:06 +00:00
|
|
|
name: 'snowpack-hmx',
|
|
|
|
knownEntrypoints: ['deepmerge'],
|
2021-03-15 17:22:05 +00:00
|
|
|
resolve: {
|
2021-03-19 20:55:06 +00:00
|
|
|
input: ['.hmx', '.md'],
|
|
|
|
output: ['.js'],
|
2021-03-15 17:22:05 +00:00
|
|
|
},
|
|
|
|
async load({ filePath }) {
|
2021-03-21 07:44:42 +00:00
|
|
|
const { compileComponent } = await transformPromise;
|
2021-03-18 17:25:19 +00:00
|
|
|
const projectRoot = snowpackConfig.root;
|
2021-03-19 20:55:06 +00:00
|
|
|
const contents = await readFile(filePath, 'utf-8');
|
2021-03-18 17:25:19 +00:00
|
|
|
const result = await compileComponent(contents, { compileOptions: { resolve }, filename: filePath, projectRoot });
|
2021-03-15 17:22:05 +00:00
|
|
|
return result.contents;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|