2021-03-19 15:55:06 -05:00
|
|
|
const { readFile } = require('fs').promises;
|
2021-03-15 12:22:05 -05:00
|
|
|
|
|
|
|
// Snowpack plugins must be CommonJS :(
|
2021-03-19 15:55:06 -05:00
|
|
|
const transformPromise = import('./lib/transform2.js');
|
2021-03-15 12:22:05 -05:00
|
|
|
|
2021-03-23 12:47:54 -05:00
|
|
|
module.exports = function (snowpackConfig, { resolve, extensions } = {}) {
|
2021-03-15 12:22:05 -05:00
|
|
|
return {
|
2021-03-19 15:55:06 -05:00
|
|
|
name: 'snowpack-hmx',
|
|
|
|
knownEntrypoints: ['deepmerge'],
|
2021-03-15 12:22:05 -05:00
|
|
|
resolve: {
|
2021-03-19 15:55:06 -05:00
|
|
|
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;
|
2021-03-18 12:25:19 -05:00
|
|
|
const projectRoot = snowpackConfig.root;
|
2021-03-19 15:55:06 -05:00
|
|
|
const contents = await readFile(filePath, 'utf-8');
|
2021-03-23 12:47:54 -05:00
|
|
|
const compileOptions = {
|
|
|
|
resolve,
|
|
|
|
extensions
|
|
|
|
};
|
|
|
|
const result = await compileComponent(contents, { compileOptions, filename: filePath, projectRoot });
|
2021-03-15 12:22:05 -05:00
|
|
|
return result.contents;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|