Skip to content

Commit

Permalink
refactor: Remove --preload flag (#1737)
Browse files Browse the repository at this point in the history
* refactor: Removes `--preload` flag & functionality

* docs: Adding changeset

* docs: Updating readme for removal of preload
  • Loading branch information
rschristian committed Aug 18, 2022
1 parent 641537d commit 3d11af1
Show file tree
Hide file tree
Showing 23 changed files with 28 additions and 410 deletions.
5 changes: 5 additions & 0 deletions .changeset/poor-sloths-mate.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'preact-cli': major
---

Removes `--preload` flag and functionality from build command.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ $ [npm run / yarn] preact build
--babelConfig Path to custom Babel config (default .babelrc)
--json Generate build stats for bundle analysis
--template Path to custom HTML template (default 'src/template.html')
--preload Adds preload tags to the document its assets (default false)
--analyze Launch interactive Analyzer to inspect production bundle(s)
--prerender Renders route(s) into generated static HTML (default true)
--prerenderUrls Path to pre-rendered routes config (default prerender-urls.json)
Expand Down
1 change: 0 additions & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
"webpack": "^5.67.0",
"webpack-bundle-analyzer": "^4.5.0",
"webpack-dev-server": "^4.9.0",
"webpack-manifest-plugin": "^5.0.0",
"webpack-merge": "^5.8.0",
"webpack-remove-empty-scripts": "^0.7.2",
"workbox-cacheable-response": "^6.5.3",
Expand Down
5 changes: 0 additions & 5 deletions packages/cli/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ prog
'--template',
'Path to custom HTML template (default "src/template.html")'
)
.option(
'--preload',
'Adds preload links to the HTML for required resources',
false
)
.option(
'--analyze',
'Launch interactive Analyzer to inspect production bundle(s)',
Expand Down
69 changes: 0 additions & 69 deletions packages/cli/src/lib/webpack/create-load-manifest.js

This file was deleted.

32 changes: 0 additions & 32 deletions packages/cli/src/lib/webpack/push-manifest.js

This file was deleted.

11 changes: 0 additions & 11 deletions packages/cli/src/lib/webpack/render-html-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const {
} = require('html-webpack-skip-assets-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const prerender = require('./prerender');
const createLoadManifest = require('./create-load-manifest');
const { error, esmImport, tryResolveConfig, warn } = require('../../util');

const PREACT_FALLBACK_URL = '/200.html';
Expand Down Expand Up @@ -79,26 +78,16 @@ module.exports = async function renderHTMLPlugin(config) {
entryFiles.find(file => /\.(m?js)(\?|$)/.test(file));
});

let loadManifest = compilation.assets['push-manifest.json']
? JSON.parse(compilation.assets['push-manifest.json'].source())
: createLoadManifest(
compilation.assets,
compilation.namedChunkGroups,
config.isProd
);

return {
cli: {
title,
url,
manifest: config.manifest,
inlineCss: config['inline-css'],
preload: config.preload,
config,
prerenderData: values,
CLI_DATA: { prerenderData: { url, ...routeData } },
ssr: config.prerender ? prerender({ cwd, dest, src }, values) : '',
loadManifest,
entrypoints,
},
htmlWebpackPlugin: {
Expand Down
10 changes: 0 additions & 10 deletions packages/cli/src/lib/webpack/webpack-base-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const ProgressBarPlugin = require('progress-bar-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const createBabelConfig = require('../babel-config');
const loadPostcssConfig = require('postcss-load-config');
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');

function readJson(file) {
try {
Expand Down Expand Up @@ -298,15 +297,6 @@ module.exports = function createBaseConfig(env) {
summary: false,
clear: true,
}),
new WebpackManifestPlugin({
fileName: 'asset-manifest.json',
assetHookStage: webpack.Compiler.PROCESS_ASSETS_STAGE_ANALYSE,
// TODO: Remove this next breaking change and use the full filepath from this manifest
// when referring to built assets, i.e.:
// https://github.com/preactjs/preact-cli/blob/master/packages/cli/src/resources/head-end.ejs#L1
// This is just to avoid any potentially breaking changes for right now.
publicPath: '',
}),
tsconfig &&
new ForkTsCheckerWebpackPlugin({
typescript: {
Expand Down
2 changes: 0 additions & 2 deletions packages/cli/src/lib/webpack/webpack-client-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
const CrittersPlugin = require('critters-webpack-plugin');
const renderHTMLPlugin = require('./render-html-plugin');
const PushManifestPlugin = require('./push-manifest');
const baseConfig = require('./webpack-base-config');
const { InjectManifest } = require('workbox-webpack-plugin');
const CompressionPlugin = require('compression-webpack-plugin');
Expand Down Expand Up @@ -123,7 +122,6 @@ async function clientConfig(env) {
'process.env.ADD_SW': env.sw,
'process.env.PRERENDER': env.prerender,
}),
new PushManifestPlugin(env.isProd),
...(await renderHTMLPlugin(env)),
copyPatterns.length !== 0 &&
new CopyWebpackPlugin({
Expand Down
7 changes: 0 additions & 7 deletions packages/cli/src/resources/head-end.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,3 @@
<% if (cli.manifest.theme_color) { %>
<meta name="theme-color" content="<%= cli.manifest.theme_color %>">
<% } %>
<% const filesRegexp = cli.inlineCss ? /\.(chunk\.\w{5}\.css|js)$/ : /\.(css|js)$/;%>
<% for (const file in cli.loadManifest[cli.url]) { %>
<% if (cli.preload && file && file.match(filesRegexp)) { %>
<% /* crossorigin for main bundle as that is loaded from `<script type=module` tag, other lazy loaded bundles are from webpack so its not needed */ %>
<link rel="preload" href="<%= htmlWebpackPlugin.files.publicPath + file %>" as="<%= file.match(/\.css$/)?'style':'script' %>" <%= file.match(/bundle\.\w{5}\.(?<!legacy)\.js$/)?'crossorigin="anonymous"':'' %>>
<% } %>
<% } %>
68 changes: 0 additions & 68 deletions packages/cli/tests/build.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,58 +90,6 @@ describe('preact build', () => {
expect(await access(file)).toBeUndefined();
});

describe('Push manifest plugin', () => {
it('should produce correct default `push-manifest.json`', async () => {
let dir = await create('default');

await buildFast(dir);
const manifest = await readFile(
`${dir}/build/push-manifest.json`,
'utf8'
);
expect(manifest).toEqual(
expect.stringMatching(getRegExpFromMarkup(images.pushManifest))
);
});

it('should produce correct `push-manifest.json` when expected values are missing', async () => {
// In this subject, there is no source CSS which means no CSS asset is output.
// In the past, this would result in `"undefined": { type: "style" ... }` being added to the manifest.
let dir = await subject('custom-webpack');
await buildFast(dir);
const manifest = await readFile(
`${dir}/build/push-manifest.json`,
'utf8'
);
expect(manifest).not.toMatch(/"undefined"/);
});

// Issue #1675
it('should produce correct `push-manifest.json` when user configures output filenames', async () => {
let dir = await subject('custom-webpack');

const config = await readFile(`${dir}/preact.config.js`, 'utf8');
await writeFile(
`${dir}/preact.config.js`,
config.replace(
"config.output.filename = '[name].js'",
"config.output.filename = 'scripts/[name].js'"
)
);

await buildFast(dir, { prerender: false });
const manifest = await readFile(
`${dir}/build/push-manifest.json`,
'utf8'
);
expect(manifest).toEqual(
expect.stringMatching(
getRegExpFromMarkup(images.pushManifestAlteredFilenames)
)
);
});
});

it('should use a custom `.env` with prefixed environment variables', async () => {
let dir = await subject('custom-dotenv');
await buildFast(dir);
Expand Down Expand Up @@ -253,22 +201,6 @@ describe('preact build', () => {
);
});

it('--preload', async () => {
let dir = await subject('preload-chunks');

await buildFast(dir, { preload: true });
let head = await getHead(dir);
expect(head).toEqual(
expect.stringMatching(getRegExpFromMarkup(images.preload.true))
);

await buildFast(dir, { preload: false });
head = await getHead(dir);
expect(head).toEqual(
expect.stringMatching(getRegExpFromMarkup(images.preload.false))
);
});

it('--prerender', async () => {
let dir = await subject('minimal');

Expand Down
Loading

0 comments on commit 3d11af1

Please sign in to comment.