-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.js
More file actions
28 lines (26 loc) · 935 Bytes
/
plugin.js
File metadata and controls
28 lines (26 loc) · 935 Bytes
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
const posthtml = require('posthtml');
const posthtmlrc = require('posthtml-load-config');
const path = require('path');
// TODO: track where roots are in PostHTML config; update HTMLs accordingly
// const roots = new Set();
module.exports = function (snowpackConfig, { root = '', configOptions = {} }) {
return {
name: 'snowpack-plugin-posthtml',
async transform({ fileExt, contents }) {
if (fileExt === '.html') {
const { plugins: postPlugins, options: postOptions } = await posthtmlrc(
configOptions.ctx,
configOptions.postPath,
configOptions.options,
);
return (await posthtml(postPlugins).process(contents, postOptions))
.html;
}
},
onChange({ filePath }) {
const basename = path.basename(filePath);
if (basename.includes('posthtml'))
this.markChanged(path.join(process.cwd(), root, '/index.html'));
},
};
};