Skip to content

Instantly share code, notes, and snippets.

@mckabi
Last active April 20, 2021 23:54
Show Gist options
  • Save mckabi/9f7589f8eb753225589464410215b929 to your computer and use it in GitHub Desktop.
Save mckabi/9f7589f8eb753225589464410215b929 to your computer and use it in GitHub Desktop.
snowpack + posthtml
module.exports = (ctx) => {
return {
parser: ctx.ext ==='.sml' ? 'posthtml-sugarss' : false,
from: ctx.from,
to: ctx.to,
path: ctx.cwd || './src',
plugins: ctx.plugins || {},
}
}
const posthtml = require('posthtml');
const posthtmlrc = require('posthtml-load-config');
module.exports = function (_snowpackConfig, _pluginOptions) {
const posthtmlConfigPromise = posthtmlrc(_pluginOptions);
return {
name: 'posthtml-transform',
// async transform({ id, contents, isDev, fileExt })
async transform({ contents, fileExt }) {
if (!['.html', '.posthtml'].includes(fileExt) || !contents) return;
const { plugins, options } = await posthtmlConfigPromise;
const stdout = await posthtml(plugins).process(contents, options);
return stdout.html;
},
};
};
/** @type {import("snowpack").SnowpackUserConfig } */
module.exports = {
mount: {
public: { url: '/', static: true },
src: { url: '/' },
},
plugins: [
['./snowpack-plugin-posthtml', {
plugins: {
'posthtml-modules': { root: './src', },
},
}],
// ... SNIP
],
// ... SNIP
};
@mckabi
Copy link
Author

mckabi commented Apr 20, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment