Skip to content

Commit 4953687

Browse files
authored
refactor: Remove --preload flag (#1737)
* refactor: Removes `--preload` flag & functionality * docs: Adding changeset * docs: Updating readme for removal of preload
1 parent 3e86e81 commit 4953687

File tree

20 files changed

+5
-356
lines changed

20 files changed

+5
-356
lines changed

.changeset/poor-sloths-mate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'preact-cli': major
3+
---
4+
5+
Removes `--preload` flag and functionality from build command.

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ $ [npm run / yarn] preact build
125125
--babelConfig Path to custom Babel config (default .babelrc)
126126
--json Generate build stats for bundle analysis
127127
--template Path to custom HTML template (default 'src/template.html')
128-
--preload Adds preload tags to the document its assets (default false)
129128
--analyze Launch interactive Analyzer to inspect production bundle(s)
130129
--prerender Renders route(s) into generated static HTML (default true)
131130
--prerenderUrls Path to pre-rendered routes config (default prerender-urls.json)

packages/cli/lib/commands/build.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ const options = [
3939
name: '--template',
4040
description: 'Path to custom HTML template (default "src/template.html")',
4141
},
42-
{
43-
name: '--preload',
44-
description: 'Adds preload tags to the document its assets',
45-
default: false,
46-
},
4742
{
4843
name: '--analyze',
4944
description: 'Launch interactive Analyzer to inspect production bundle(s)',

packages/cli/lib/lib/webpack/create-load-manifest.js

Lines changed: 0 additions & 68 deletions
This file was deleted.

packages/cli/lib/lib/webpack/push-manifest.js

Lines changed: 0 additions & 28 deletions
This file was deleted.

packages/cli/lib/lib/webpack/render-html-plugin.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const {
77
} = require('html-webpack-skip-assets-plugin');
88
const HtmlWebpackPlugin = require('html-webpack-plugin');
99
const prerender = require('./prerender');
10-
const createLoadManifest = require('./create-load-manifest');
1110
const { esmImport, tryResolveConfig, warn } = require('../../util');
1211

1312
const PREACT_FALLBACK_URL = '/200.html';
@@ -82,14 +81,6 @@ module.exports = async function renderHTMLPlugin(config) {
8281
entryFiles.find(file => /\.(m?js)(\?|$)/.test(file));
8382
});
8483

85-
let loadManifest = compilation.assets['push-manifest.json']
86-
? JSON.parse(compilation.assets['push-manifest.json'].source())
87-
: createLoadManifest(
88-
compilation.assets,
89-
compilation.namedChunkGroups,
90-
config.isProd
91-
);
92-
9384
return {
9485
cli: {
9586
title,
@@ -101,7 +92,6 @@ module.exports = async function renderHTMLPlugin(config) {
10192
preRenderData: values,
10293
CLI_DATA: { preRenderData: { url, ...routeData } },
10394
ssr: config.prerender ? prerender({ cwd, dest, src }, values) : '',
104-
loadManifest,
10595
entrypoints,
10696
},
10797
htmlWebpackPlugin: {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
1010
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
1111
const CrittersPlugin = require('critters-webpack-plugin');
1212
const renderHTMLPlugin = require('./render-html-plugin');
13-
const PushManifestPlugin = require('./push-manifest');
1413
const baseConfig = require('./webpack-base-config');
1514
const { InjectManifest } = require('workbox-webpack-plugin');
1615
const CompressionPlugin = require('compression-webpack-plugin');
@@ -132,7 +131,6 @@ async function clientConfig(env) {
132131
'process.env.ADD_SW': env.sw,
133132
'process.env.PRERENDER': env.prerender,
134133
}),
135-
new PushManifestPlugin(env.isProd),
136134
...(await renderHTMLPlugin(env)),
137135
copyPatterns.length !== 0 &&
138136
new CopyWebpackPlugin({

packages/cli/lib/resources/head-end.ejs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,3 @@
22
<% if (cli.manifest.theme_color) { %>
33
<meta name="theme-color" content="<%= cli.manifest.theme_color %>">
44
<% } %>
5-
<% const filesRegexp = cli.inlineCss ? /\.(chunk\.\w{5}\.css|js)$/ : /\.(css|js)$/;%>
6-
<% for (const file in cli.loadManifest[cli.url]) { %>
7-
<% if (cli.preload && file && file.match(filesRegexp)) { %>
8-
<% /* crossorigin for main bundle as that is loaded from `<script type=module` tag, other lazy loaded bundles are from webpack so its not needed */ %>
9-
<link rel="preload" href="<%= htmlWebpackPlugin.files.publicPath + file %>" as="<%= file.match(/\.css$/)?'style':'script' %>" <%= file.match(/bundle\.\w{5}\.(?<!legacy)\.js$/)?'crossorigin="anonymous"':'' %>>
10-
<% } %>
11-
<% } %>

packages/cli/tests/build.test.js

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -97,58 +97,6 @@ describe('preact build', () => {
9797
expect(await access(file)).toBeUndefined();
9898
});
9999

100-
describe('Push manifest plugin', () => {
101-
it('should produce correct default `push-manifest.json`', async () => {
102-
let dir = await create('default');
103-
104-
await buildFast(dir);
105-
const manifest = await readFile(
106-
`${dir}/build/push-manifest.json`,
107-
'utf8'
108-
);
109-
expect(manifest).toEqual(
110-
expect.stringMatching(getRegExpFromMarkup(images.pushManifest))
111-
);
112-
});
113-
114-
it('should produce correct `push-manifest.json` when expected values are missing', async () => {
115-
// In this subject, there is no source CSS which means no CSS asset is output.
116-
// In the past, this would result in `"undefined": { type: "style" ... }` being added to the manifest.
117-
let dir = await subject('custom-webpack');
118-
await buildFast(dir);
119-
const manifest = await readFile(
120-
`${dir}/build/push-manifest.json`,
121-
'utf8'
122-
);
123-
expect(manifest).not.toMatch(/"undefined"/);
124-
});
125-
126-
// Issue #1675
127-
it('should produce correct `push-manifest.json` when user configures output filenames', async () => {
128-
let dir = await subject('custom-webpack');
129-
130-
const config = await readFile(`${dir}/preact.config.js`, 'utf8');
131-
await writeFile(
132-
`${dir}/preact.config.js`,
133-
config.replace(
134-
"config.output.filename = '[name].js'",
135-
"config.output.filename = 'scripts/[name].js'"
136-
)
137-
);
138-
139-
await buildFast(dir, { prerender: false });
140-
const manifest = await readFile(
141-
`${dir}/build/push-manifest.json`,
142-
'utf8'
143-
);
144-
expect(manifest).toEqual(
145-
expect.stringMatching(
146-
getRegExpFromMarkup(images.pushManifestAlteredFilenames)
147-
)
148-
);
149-
});
150-
});
151-
152100
it('should use a custom `.env` with prefixed environment variables', async () => {
153101
let dir = await subject('custom-dotenv');
154102
await buildFast(dir);
@@ -260,22 +208,6 @@ describe('preact build', () => {
260208
);
261209
});
262210

263-
it('--preload', async () => {
264-
let dir = await subject('preload-chunks');
265-
266-
await buildFast(dir, { preload: true });
267-
let head = await getHead(dir);
268-
expect(head).toEqual(
269-
expect.stringMatching(getRegExpFromMarkup(images.preload.true))
270-
);
271-
272-
await buildFast(dir, { preload: false });
273-
head = await getHead(dir);
274-
expect(head).toEqual(
275-
expect.stringMatching(getRegExpFromMarkup(images.preload.false))
276-
);
277-
});
278-
279211
it('--prerender', async () => {
280212
let dir = await subject('minimal');
281213

packages/cli/tests/images/build.js

Lines changed: 0 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ exports.default = {
2828
'index.html': 2263,
2929
'manifest.json': 455,
3030
'preact_prerender_data.json': 11,
31-
'push-manifest.json': 450,
3231
'asset-manifest.json': 943,
3332

3433
'route-home.chunk.4ad71.js': 339,
@@ -100,45 +99,6 @@ exports.prerender.heads.custom = `
10099
<\\/head>
101100
`;
102101

103-
exports.preload = {};
104-
105-
exports.preload.true = `
106-
<head>
107-
<meta charset=\\"utf-8\\">
108-
<title>preact-preload-chunks<\\/title>
109-
<meta name=\\"viewport\\" content=\\"width=device-width,initial-scale=1\\">
110-
<meta name=\\"mobile-web-app-capable\\" content=\\"yes\\">
111-
<meta name=\\"apple-mobile-web-app-capable\\" content=\\"yes\\">
112-
<link rel=\\"apple-touch-icon\\" href=\\"\\/assets\\/icons\\/apple-touch-icon\\.png\\">
113-
<link rel=\\"manifest\\" href=\\"\\/manifest\\.json\\">
114-
<link rel=\\"preload\\" href=\\"\\/bundle\\.\\w{5}\\.js\\" as=\\"script\\">
115-
<link rel=\\"preload\\" href=\\"\\/route-home\\.chunk\\.\\w{5}\\.js\\" as=\\"script\\">
116-
<link rel=\\"preload\\" href=\\"\\/route-home\\.chunk\\.\\w{5}\\.css\\" as=\\"style\\">
117-
<style>html{padding:0}<\\/style>
118-
<link href=\\"\\/bundle\\.\\w{5}\\.css\\" rel=\\"stylesheet\\" media=\\"print\\" onload=\\"this.media='all'\\">
119-
<noscript>
120-
<link rel=\\"stylesheet\\" href=\\"\\/bundle.\\w{5}.css\\">
121-
</noscript>
122-
</head>
123-
`;
124-
125-
exports.preload.false = `
126-
<head>
127-
<meta charset=\\"utf-8\\">
128-
<title>preact-preload-chunks<\\/title>
129-
<meta name=\\"viewport\\" content=\\"width=device-width,initial-scale=1\\">
130-
<meta name=\\"mobile-web-app-capable\\" content=\\"yes\\">
131-
<meta name=\\"apple-mobile-web-app-capable\\" content=\\"yes\\">
132-
<link rel=\\"apple-touch-icon\\" href=\\"\\/assets\\/icons\\/apple-touch-icon\\.png\\">
133-
<link rel=\\"manifest\\" href=\\"\\/manifest\\.json\\">
134-
<style>html{padding:0}<\\/style>
135-
<link href=\\"\\/bundle\\.\\w{5}\\.css\\" rel=\\"stylesheet\\" media=\\"print\\" onload=\\"this.media='all'\\">
136-
<noscript>
137-
<link rel=\\"stylesheet\\" href=\\"\\/bundle.\\w{5}.css\\">
138-
</noscript>
139-
</head>
140-
`;
141-
142102
exports.prerender.home = `
143103
<body>
144104
<div id="app">
@@ -207,58 +167,6 @@ exports.template = `
207167
</html>
208168
`;
209169

210-
exports.pushManifest = `
211-
{
212-
"/":{
213-
"bundle.\\w{5}.css":{
214-
"type":"style",
215-
"weight":1
216-
},
217-
"bundle.\\w{5}.js":{
218-
"type":"script",
219-
"weight":1
220-
},
221-
"route-home.chunk.\\w{5}.js":{
222-
"type":"script",
223-
"weight":0.9
224-
},
225-
"route-home.chunk.\\w{5}.css":{
226-
"type":"style",
227-
"weight":0.9
228-
}
229-
},
230-
"/profile":{
231-
"bundle.\\w{5}.css":{
232-
"type":"style",
233-
"weight":1
234-
},
235-
"bundle.\\w{5}.js":{
236-
"type":"script",
237-
"weight":1
238-
},
239-
"route-profile.chunk.\\w{5}.js":{
240-
"type":"script",
241-
"weight":0.9
242-
},
243-
"route-profile.chunk.\\w{5}.css":{
244-
"type":"style",
245-
"weight":0.9
246-
}
247-
}
248-
}
249-
`;
250-
251-
exports.pushManifestAlteredFilenames = `
252-
{
253-
"/":{
254-
"scripts/bundle.js":{
255-
"type":"script",
256-
"weight":1
257-
}
258-
}
259-
}
260-
`;
261-
262170
exports.publicPath = `
263171
<!DOCTYPE html>
264172
<html lang="en">

0 commit comments

Comments
 (0)