-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
snowpack-plugin.cjs
31 lines (29 loc) · 937 Bytes
/
snowpack-plugin.cjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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: [],
resolve: {
input: ['.astro', '.md'],
output: ['.js', '.css'],
},
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 });
const output = {
'.js': result.contents,
};
if (result.css) output['.css'] = result.css;
return output;
},
};
};