4a732837cd
Previously dynamic component URLs were being resolved client-side in a weird way that only worked during dev. This change makes them handle during compilation, so it works in both (and improves readability of the dynamic import output).
27 lines
834 B
JavaScript
27 lines
834 B
JavaScript
const { readFile } = require('fs').promises;
|
|
|
|
// Snowpack plugins must be CommonJS :(
|
|
const transformPromise = import('./lib/compiler/index.js');
|
|
|
|
module.exports = function (snowpackConfig, { resolve, extensions, astroConfig } = {}) {
|
|
return {
|
|
name: 'snowpack-astro',
|
|
knownEntrypoints: ['deepmerge'],
|
|
resolve: {
|
|
input: ['.astro', '.md'],
|
|
output: ['.js'],
|
|
},
|
|
async load({ filePath }) {
|
|
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 });
|
|
return result.contents;
|
|
},
|
|
};
|
|
};
|