Last active
April 20, 2021 23:54
-
-
Save mckabi/9f7589f8eb753225589464410215b929 to your computer and use it in GitHub Desktop.
snowpack + posthtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = (ctx) => { | |
return { | |
parser: ctx.ext ==='.sml' ? 'posthtml-sugarss' : false, | |
from: ctx.from, | |
to: ctx.to, | |
path: ctx.cwd || './src', | |
plugins: ctx.plugins || {}, | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
}, | |
}; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** @type {import("snowpack").SnowpackUserConfig } */ | |
module.exports = { | |
mount: { | |
public: { url: '/', static: true }, | |
src: { url: '/' }, | |
}, | |
plugins: [ | |
['./snowpack-plugin-posthtml', { | |
plugins: { | |
'posthtml-modules': { root: './src', }, | |
}, | |
}], | |
// ... SNIP | |
], | |
// ... SNIP | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/mckabi/snowpack-posthtml