Replies: 2 comments 5 replies
-
You'll need to re-initialize the plugin in cases like this, which is a bit annoying but no real way around:
import CrittersPlugin from 'critters-webpack-plugin';
export default (config, env, helpers) => {
const critters = helpers.getPluginsByName(config, 'Critters');
if (critters.length) {
const { index } = critters[0];
config.plugins[index] = new CrittersPlugin({
preload: 'media',
pruneSource: false,
logLevel: 'debug',
additionalStylesheets: ['*.css'],
});
}
} The |
Beta Was this translation helpful? Give feedback.
-
Thanks @rschristian! It turns out the issue was using Emotion with an Here's a reduced test case. You can add the # Setup default Preact CLI project
npx preact-cli create default preact-emotion-demo
cd preact-emotion-demo
# Install Emotion
npm i @emotion/react @emotion/styled
npm i -D @emotion/babel-plugin Setup URLs to pre-render // src/prerender-urls.js (new file)
module.exports = [
{ url: '/' },
{ url: '/profile' },
] Update the "scripts": {
"build": "preact build --prerenderUrls src/prerender-urls.js", Create // components/header/emotion-styles.js (new file)
import styled from '@emotion/styled';
export const Nav = styled.nav`
background: red;
` Wrap // components/header/index.js (modified file)
import { h } from 'preact';
import { Link } from 'preact-router/match';
import style from './style.css';
import { Nav } from './emotion-styles';
import createCache from '@emotion/cache';
import { CacheProvider as EmotionCacheProvider } from '@emotion/react';
const emotionCache = createCache({ key: 'css' });
const Header = () => (
<header class={style.header}>
<h1>Preact App</h1>
<EmotionCacheProvider value={emotionCache}>
<Nav>
<Link activeClassName={style.active} href="/">Home</Link>
<Link activeClassName={style.active} href="/profile">Me</Link>
<Link activeClassName={style.active} href="/profile/john">John</Link>
</Nav>
</EmotionCacheProvider>
</header>
);
export default Header; Run
Thanks again for your help with this! |
Beta Was this translation helpful? Give feedback.
-
Hi, I was wondering how to debug critical CSS generation with Critter.
I'm pre-rendering several routes (e.g.
/
,/library
,/search
, etc), and for some reason my top navigation bar's CSS is only included in the root/
route, not on any of the other pages (where it shows up unstyled if JavaScript is disabled, or I get FOUC if JavaScript is enabled).Root route:
Other routes:
I'm guessing it has something to do with file paths. I tried changing to
additionalStylesheets
to**/*.css
but that didn't help. I expect I'd be able to figure it out if I was able to get any log output from the Critter webpack plugin, but it's unclear to me how to do that. I can change the logLevel todebug
inpreact.config.js
, but that doesn't appear to have any effect, as the Critter instance already has alogger
instance withlevel: 'silent'
Thanks for your help!
Beta Was this translation helpful? Give feedback.
All reactions