使用Preact Build时,如何保持模板HTML中的样式标记



我正在使用Preact 3.0。我在模板index.html文件中有一些style标记。目的是在建造过程中保持它。例如,

<style id="keep-this-tag">
some-styles-that-should-not-be-put-in-style.css-file
</style>

您需要标签本身来保留吗?

如果是这样,只需使用以下配置,或添加到现有配置中:

// preact.config.js
export default (config, env, helpers) => {
const critters = helpers.getPluginsByName(config, 'Critters')[0];
if (critters) {
critters.plugin.options.mergeStylesheets = false;
}
}

Critters用于关键的CSS内联,默认情况下,它将样式标记合并在一起。虽然很容易残疾,但希望这能有所帮助。

编辑:在禁用预呈现的情况下,Critters将剥离所有CSS,就像人们认为的那样;未使用";。要禁用Critters,可以使用--no-inline-css标志,即preact build --no-inline-css

你确实失去了内联,但没有办法绕过它

最新更新