Skip to content

Commit 7c811ac

Browse files
authored
refactor: Remove Critters (perhaps temporarily) (#1778)
* refactor: Remove Critters (perhaps temporarily) * docs: Adding changeset
1 parent 21c570f commit 7c811ac

File tree

8 files changed

+22
-118
lines changed

8 files changed

+22
-118
lines changed

.changeset/few-panthers-admire.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'preact-cli': major
3+
---
4+
5+
Removes Critters which facilitates automatic CSS inlining in prod.
6+
7+
Unfortunately Critters has not been updated for Webpack v5, resulting in a precarious dependency situation that causes issues for NPM users. As such, Critters will be removed for the time being.
8+
9+
It may be updated or we may switch to a fork, but for now, it's causing issues and will require some work to correct.

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ $ [npm init / yarn create] preact-cli <template-name> <project-name>
113113

114114
Create a production build
115115

116-
You can disable `default: true` flags by prefixing them with `--no-<option>`; for example, `--no-sw`, `--no-prerender`, and `--no-inline-css`.
116+
You can disable `default: true` flags by prefixing them with `--no-<option>`; for example, `--no-sw` and `--no-prerender`.
117117

118118
```
119119
$ [npm run / yarn] preact build
@@ -126,7 +126,6 @@ $ [npm run / yarn] preact build
126126
--prerender Renders route(s) into generated static HTML (default true)
127127
--prerenderUrls Path to pre-rendered routes config (default prerender-urls.json)
128128
--template Path to custom EJS or HTML template (default 'src/template.ejs')
129-
--inlineCss Adds critical css to the prerendered markup (default true)
130129
--analyze Launch interactive Analyzer to inspect production bundle(s) (default false)
131130
-c, --config Path to custom CLI config (default preact.config.js)
132131
-v, --verbose Verbose output

packages/cli/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"browserslist": "^4.20.3",
4949
"console-clear": "^1.0.0",
5050
"copy-webpack-plugin": "^9.1.0",
51-
"critters-webpack-plugin": "^3.0.2",
5251
"css-loader": "^6.6.0",
5352
"css-minimizer-webpack-plugin": "3.4.1",
5453
"dotenv": "^16.0.0",

packages/cli/src/index.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ prog
4646
'Path to prerendered routes config',
4747
'prerender-urls.json'
4848
)
49-
.option('--inlineCss', 'Adds critical CSS to the prerendered HTML', true)
5049
.option('-c, --config', 'Path to custom CLI config', 'preact.config.js')
5150
.option('-v, --verbose', 'Verbose output', false)
5251
.action(argv => exec(build(argv)));
@@ -85,9 +84,6 @@ prog
8584
.action(() => exec(info()));
8685

8786
prog.parse(process.argv, {
88-
alias: {
89-
inlineCss: ['inline-css'],
90-
},
9187
unknown: arg => {
9288
const cmd = process.argv[2];
9389
error(

packages/cli/src/lib/webpack/webpack-client-config.js

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const CopyWebpackPlugin = require('copy-webpack-plugin');
88
const TerserPlugin = require('terser-webpack-plugin');
99
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
1010
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
11-
const CrittersPlugin = require('critters-webpack-plugin');
1211
const renderHTMLPlugin = require('./render-html-plugin');
1312
const baseConfig = require('./webpack-base-config');
1413
const { InjectManifest } = require('workbox-webpack-plugin');
@@ -190,17 +189,6 @@ function prodBuild(config) {
190189
},
191190
};
192191

193-
if (config.inlineCss) {
194-
prodConfig.plugins.push(
195-
new CrittersPlugin({
196-
preload: 'media',
197-
pruneSource: false,
198-
logLevel: 'silent',
199-
additionalStylesheets: ['route-*.css'],
200-
})
201-
);
202-
}
203-
204192
if (config.analyze) {
205193
prodConfig.plugins.push(new BundleAnalyzerPlugin());
206194
}

packages/cli/tests/build.test.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,6 @@ describe('preact build', () => {
231231
).toBeUndefined();
232232
});
233233

234-
it('--inlineCss', async () => {
235-
let dir = await subject('minimal');
236-
237-
await buildFast(dir, { inlineCss: true });
238-
let head = await getHead(dir);
239-
expect(head).toMatch('<style>h1{color:red}</style>');
240-
241-
await buildFast(dir, { inlineCss: false });
242-
head = await getOutputFile(dir, 'index.html');
243-
expect(head).not.toMatch(/<style>[^<]*<\/style>/);
244-
});
245-
246234
it('--config', async () => {
247235
let dir = await subject('custom-webpack');
248236

@@ -296,16 +284,6 @@ describe('preact build', () => {
296284
expect(builtStylesheet).toMatch(/\.text__\w{5}{color:blue}/);
297285
});
298286

299-
it('should inline critical CSS only', async () => {
300-
let dir = await subject('css-inline');
301-
await buildFast(dir);
302-
const builtStylesheet = await getOutputFile(dir, /bundle\.\w{5}\.css$/);
303-
const html = await getOutputFile(dir, 'index.html');
304-
305-
expect(builtStylesheet).toMatch('h1{color:red}div{background:tan}');
306-
expect(html).toMatch('<style>h1{color:red}</style>');
307-
});
308-
309287
// Issue #1411
310288
it('should preserve side-effectful CSS imports even if package.json claims no side effects', async () => {
311289
let dir = await subject('css-side-effect');

packages/cli/tests/images/build.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ exports.default = {
2626
'es-polyfills.js': 42690,
2727

2828
'favicon.ico': 15086,
29-
'index.html': 3998,
29+
'index.html': 1972,
3030
'manifest.json': 455,
3131
'preact_prerender_data.json': 11,
3232

@@ -55,11 +55,7 @@ exports.prerender.heads.home = `
5555
<meta name="apple-mobile-web-app-capable" content="yes">
5656
<link rel="apple-touch-icon" href=\\"\\/assets\\/icons\\/apple-touch-icon\\.png\\">
5757
<link rel="manifest" href="\\/manifest\\.json">
58-
<style>html{padding:0}<\\/style>
59-
<link href=\\"/bundle.\\w{5}.css\\" rel=\\"stylesheet\\" media=\\"print\\" onload=\\"this.media='all'\\">
60-
<noscript>
61-
<link rel=\\"stylesheet\\" href=\\"\\/bundle.\\w{5}.css\\">
62-
</noscript>
58+
<link href=\\"/bundle.\\w{5}.css\\" rel=\\"stylesheet\\">
6359
<\\/head>
6460
`;
6561

@@ -72,11 +68,7 @@ exports.prerender.heads.route66 = `
7268
<meta name="apple-mobile-web-app-capable" content="yes">
7369
<link rel="apple-touch-icon" href=\\"\\/assets\\/icons\\/apple-touch-icon\\.png\\">
7470
<link rel="manifest" href="\\/manifest\\.json">
75-
<style>html{padding:0}<\\/style>
76-
<link href=\\"/bundle.\\w{5}.css\\" rel=\\"stylesheet\\" media=\\"print\\" onload=\\"this.media='all'\\">
77-
<noscript>
78-
<link rel=\\"stylesheet\\" href=\\"\\/bundle.\\w{5}.css\\">
79-
</noscript>
71+
<link href=\\"/bundle.\\w{5}.css\\" rel=\\"stylesheet\\">
8072
<\\/head>
8173
`;
8274

@@ -89,11 +81,7 @@ exports.prerender.heads.custom = `
8981
<meta name="apple-mobile-web-app-capable" content="yes">
9082
<link rel="apple-touch-icon" href=\\"\\/assets\\/icons\\/apple-touch-icon\\.png\\">
9183
<link rel="manifest" href="\\/manifest\\.json">
92-
<style>html{padding:0}<\\/style>
93-
<link href=\\"/bundle.\\w{5}.css\\" rel=\\"stylesheet\\" media=\\"print\\" onload=\\"this.media='all'\\">
94-
<noscript>
95-
<link rel=\\"stylesheet\\" href=\\"\\/bundle.\\w{5}.css\\">
96-
</noscript>
84+
<link href=\\"/bundle.\\w{5}.css\\" rel=\\"stylesheet\\">
9785
<\\/head>
9886
`;
9987

@@ -143,7 +131,7 @@ exports.prerender.htmlSafe = `
143131
`;
144132

145133
exports.template = `
146-
<!DOCTYPE html>
134+
<!doctype html>
147135
<html lang="en">
148136
<head>
149137
<meta charset="utf-8">
@@ -159,7 +147,7 @@ exports.template = `
159147
`;
160148

161149
exports.publicPath = `
162-
<!DOCTYPE html>
150+
<!doctype html>
163151
<html lang="en">
164152
<head>
165153
<meta charset="utf-8">
@@ -175,9 +163,9 @@ exports.publicPath = `
175163
<h1>Public path test</h1>
176164
<script type="__PREACT_CLI_DATA__">%7B%22preRenderData%22:%7B%22url%22:%22/%22%7D%7D</script>
177165
<script type="module" src="/example-path/bundle.\\w{5}.js"></script>
178-
<script nomodule="" src="/example-path/dom-polyfills.\\w{5}.js"></script>
179-
<script nomodule="" src="/example-path/es-polyfills.js"></script>
180-
<script nomodule="" defer="defer" src="/example-path/bundle.\\w{5}.legacy.js"></script>
166+
<script nomodule src="/example-path/dom-polyfills.\\w{5}.js"></script>
167+
<script nomodule src="/example-path/es-polyfills.js"></script>
168+
<script nomodule defer="defer" src="/example-path/bundle.\\w{5}.legacy.js"></script>
181169
</body>
182170
</html>
183171
`;

yarn.lock

Lines changed: 3 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3734,28 +3734,6 @@ create-error-class@^3.0.0:
37343734
dependencies:
37353735
capture-stack-trace "^1.0.0"
37363736

3737-
critters-webpack-plugin@^3.0.2:
3738-
version "3.0.2"
3739-
resolved "https://registry.yarnpkg.com/critters-webpack-plugin/-/critters-webpack-plugin-3.0.2.tgz#12cbd90310ea6a6050d73e49f27fe2e623e4a90d"
3740-
integrity sha512-WdGtrjfzTGTuLL1qR9yIrPvrF+r4Fq5MsI+hfjuujLRVzh5UOl1TPCdX4kJU12iK5LFHtbNtezcAJCaXpvozHA==
3741-
dependencies:
3742-
critters "^0.0.16"
3743-
minimatch "^3.0.4"
3744-
webpack-log "^3.0.1"
3745-
webpack-sources "^1.3.0"
3746-
3747-
critters@^0.0.16:
3748-
version "0.0.16"
3749-
resolved "https://registry.yarnpkg.com/critters/-/critters-0.0.16.tgz#ffa2c5561a65b43c53b940036237ce72dcebfe93"
3750-
integrity sha512-JwjgmO6i3y6RWtLYmXwO5jMd+maZt8Tnfu7VVISmEWyQqfLpB8soBswf8/2bu6SBXxtKA68Al3c+qIG1ApT68A==
3751-
dependencies:
3752-
chalk "^4.1.0"
3753-
css-select "^4.2.0"
3754-
parse5 "^6.0.1"
3755-
parse5-htmlparser2-tree-adapter "^6.0.1"
3756-
postcss "^8.3.7"
3757-
pretty-bytes "^5.3.0"
3758-
37593737
cross-fetch@3.1.5:
37603738
version "3.1.5"
37613739
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f"
@@ -3842,7 +3820,7 @@ css-minimizer-webpack-plugin@3.4.1:
38423820
serialize-javascript "^6.0.0"
38433821
source-map "^0.6.1"
38443822

3845-
css-select@^4.1.3, css-select@^4.2.0:
3823+
css-select@^4.1.3:
38463824
version "4.2.1"
38473825
resolved "https://registry.yarnpkg.com/css-select/-/css-select-4.2.1.tgz#9e665d6ae4c7f9d65dbe69d0316e3221fb274cdd"
38483826
integrity sha512-/aUslKhzkTNCQUB2qTX84lVmfia9NyjP3WpDGtj/WxhwBzWBYUV3DgUpurHTme8UTPcPlAD1DJ+b0nN/t50zDQ==
@@ -7603,11 +7581,6 @@ log-update@^4.0.0:
76037581
slice-ansi "^4.0.0"
76047582
wrap-ansi "^6.2.0"
76057583

7606-
loglevelnext@^3.0.1:
7607-
version "3.0.1"
7608-
resolved "https://registry.yarnpkg.com/loglevelnext/-/loglevelnext-3.0.1.tgz#e3e4659c4061c09264f6812c33586dc55a009a04"
7609-
integrity sha512-JpjaJhIN1reaSb26SIxDGtE0uc67gPl19OMVHrr+Ggt6b/Vy60jmCtKgQBrygAH0bhRA2nkxgDvM+8QvR8r0YA==
7610-
76117584
loose-envify@^1.0.0, loose-envify@^1.4.0:
76127585
version "1.4.0"
76137586
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
@@ -8041,11 +8014,6 @@ nan@^2.12.1:
80418014
resolved "https://registry.yarnpkg.com/nan/-/nan-2.15.0.tgz#3f34a473ff18e15c1b5626b62903b5ad6e665fee"
80428015
integrity sha512-8ZtvEnA2c5aYCZYd1cvgdnU6cqwixRoYg70xPLWUws5ORTa/lnw+u4amixRS/Ac5U5mQVgp9pnlSUnbNWFaWZQ==
80438016

8044-
nanoid@^2.0.3:
8045-
version "2.1.11"
8046-
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-2.1.11.tgz#ec24b8a758d591561531b4176a01e3ab4f0f0280"
8047-
integrity sha512-s/snB+WGm6uwi0WjsZdaVcuf3KJXlfGl2LcxgwkEwJF0D/BWzVWAZW/XY4bFaiR7s0Jk3FPvlnepg1H1b1UwlA==
8048-
80498017
nanoid@^3.2.0:
80508018
version "3.2.0"
80518019
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.2.0.tgz#62667522da6673971cca916a6d3eff3f415ff80c"
@@ -8956,13 +8924,6 @@ parse-node-version@^1.0.1:
89568924
resolved "https://registry.yarnpkg.com/parse-node-version/-/parse-node-version-1.0.1.tgz#e2b5dbede00e7fa9bc363607f53327e8b073189b"
89578925
integrity sha512-3YHlOa/JgH6Mnpr05jP9eDG254US9ek25LyIxZlDItp2iJtwyaXQb57lBYLdT3MowkUFYEV2XXNAYIPlESvJlA==
89588926

8959-
parse5-htmlparser2-tree-adapter@^6.0.1:
8960-
version "6.0.1"
8961-
resolved "https://registry.yarnpkg.com/parse5-htmlparser2-tree-adapter/-/parse5-htmlparser2-tree-adapter-6.0.1.tgz#2cdf9ad823321140370d4dbf5d3e92c7c8ddc6e6"
8962-
integrity sha512-qPuWvbLgvDGilKc5BoicRovlT4MtYT6JfJyBOMDsKoiT+GiuP5qyrPCnR9HcPECIJJmZh5jRndyNThnhhb/vlA==
8963-
dependencies:
8964-
parse5 "^6.0.1"
8965-
89668927
parse5@4.0.0:
89678928
version "4.0.0"
89688929
resolved "https://registry.yarnpkg.com/parse5/-/parse5-4.0.0.tgz#6d78656e3da8d78b4ec0b906f7c08ef1dfe3f608"
@@ -8973,11 +8934,6 @@ parse5@^1.5.1:
89738934
resolved "https://registry.yarnpkg.com/parse5/-/parse5-1.5.1.tgz#9b7f3b0de32be78dc2401b17573ccaf0f6f59d94"
89748935
integrity sha1-m387DeMr543CQBsXVzzK8Pb1nZQ=
89758936

8976-
parse5@^6.0.1:
8977-
version "6.0.1"
8978-
resolved "https://registry.yarnpkg.com/parse5/-/parse5-6.0.1.tgz#e1a1c085c569b3dc08321184f19a39cc27f7c30b"
8979-
integrity sha512-Ofn/CTFzRGTTxwpNEs9PP93gXShHcTq255nzRYSKe8AkVpZY7e1fpmTfOyoIvjP5HG7Z2ZM7VS9PPhQGW2pOpw==
8980-
89818937
parseurl@~1.3.2, parseurl@~1.3.3:
89828938
version "1.3.3"
89838939
resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.3.tgz#9da19e7bee8d12dff0513ed5b76957793bc2e8d4"
@@ -9398,7 +9354,7 @@ postcss-value-parser@^4.1.0:
93989354
resolved "https://registry.yarnpkg.com/postcss-value-parser/-/postcss-value-parser-4.1.0.tgz#443f6a20ced6481a2bda4fa8532a6e55d789a2cb"
93999355
integrity sha512-97DXOFbQJhk71ne5/Mt6cOu6yxsSfM0QGQyl0L25Gca4yGWEGJaig7l7gbCX623VqTBNGLRLaVUCnNkcedlRSQ==
94009356

9401-
postcss@^8.3.5, postcss@^8.3.7, postcss@^8.4.5:
9357+
postcss@^8.3.5, postcss@^8.4.5:
94029358
version "8.4.6"
94039359
resolved "https://registry.yarnpkg.com/postcss/-/postcss-8.4.6.tgz#c5ff3c3c457a23864f32cb45ac9b741498a09ae1"
94049360
integrity sha512-OovjwIzs9Te46vlEx7+uXB0PLijpwjXGKXjVGGPIGubGpq7uh5Xgf6D6FiJ/SzJMBosHDp6a2hiXOS97iBXcaA==
@@ -11935,15 +11891,6 @@ webpack-dev-server@^4.9.0:
1193511891
webpack-dev-middleware "^5.3.1"
1193611892
ws "^8.4.2"
1193711893

11938-
webpack-log@^3.0.1:
11939-
version "3.0.2"
11940-
resolved "https://registry.yarnpkg.com/webpack-log/-/webpack-log-3.0.2.tgz#edf64fe4cabffeb04a03ca44d89f9908a4a9d238"
11941-
integrity sha512-ijm2zgqTY2omtlxRNrtDqxAQOrfAGMxWg9fQB/kuFSeZjx/OkYnfYLqsjf/JkrWOHINMzqxaJDXaog6Mx9KaHg==
11942-
dependencies:
11943-
chalk "^2.4.2"
11944-
loglevelnext "^3.0.1"
11945-
nanoid "^2.0.3"
11946-
1194711894
webpack-merge@^5.8.0:
1194811895
version "5.8.0"
1194911896
resolved "https://registry.yarnpkg.com/webpack-merge/-/webpack-merge-5.8.0.tgz#2b39dbf22af87776ad744c390223731d30a68f61"
@@ -11964,7 +11911,7 @@ webpack-remove-empty-scripts@^0.7.2:
1196411911
dependencies:
1196511912
ansis "^1.3.4"
1196611913

11967-
webpack-sources@^1.3.0, webpack-sources@^1.4.3:
11914+
webpack-sources@^1.4.3:
1196811915
version "1.4.3"
1196911916
resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.4.3.tgz#eedd8ec0b928fbf1cbfe994e22d2d890f330a933"
1197011917
integrity sha512-lgTS3Xhv1lCOKo7SA5TjKXMjpSM4sBjNV5+q2bqesbSPs5FjGmU6jjtBSkX9b4qW87vDIsCIlUPOEhbZrMdjeQ==

0 commit comments

Comments
 (0)