From 08ee3b3b822495ab22011e1bf3ff036f54115a13 Mon Sep 17 00:00:00 2001 From: Ryan Christian Date: Wed, 17 Aug 2022 21:50:33 -0500 Subject: [PATCH 1/3] refactor: Removes `--preload` flag & functionality --- packages/cli/lib/commands/build.js | 5 - .../lib/lib/webpack/create-load-manifest.js | 68 -------------- packages/cli/lib/lib/webpack/push-manifest.js | 28 ------ .../cli/lib/lib/webpack/render-html-plugin.js | 10 -- .../lib/lib/webpack/webpack-client-config.js | 2 - packages/cli/lib/resources/head-end.ejs | 7 -- packages/cli/tests/build.test.js | 68 -------------- packages/cli/tests/images/build.js | 92 ------------------- .../tests/subjects/preload-chunks/index.js | 24 ----- .../subjects/preload-chunks/package.json | 4 - .../subjects/preload-chunks/routes/base.js | 11 --- .../subjects/preload-chunks/routes/home.css | 3 - .../subjects/preload-chunks/routes/home.js | 8 -- .../preload-chunks/routes/route66.css | 3 - .../subjects/preload-chunks/routes/route66.js | 8 -- .../preload-chunks/routes/route89.css | 3 - .../subjects/preload-chunks/routes/route89.js | 8 -- .../tests/subjects/preload-chunks/style.css | 3 - 18 files changed, 355 deletions(-) delete mode 100644 packages/cli/lib/lib/webpack/create-load-manifest.js delete mode 100644 packages/cli/lib/lib/webpack/push-manifest.js delete mode 100644 packages/cli/tests/subjects/preload-chunks/index.js delete mode 100644 packages/cli/tests/subjects/preload-chunks/package.json delete mode 100644 packages/cli/tests/subjects/preload-chunks/routes/base.js delete mode 100644 packages/cli/tests/subjects/preload-chunks/routes/home.css delete mode 100644 packages/cli/tests/subjects/preload-chunks/routes/home.js delete mode 100644 packages/cli/tests/subjects/preload-chunks/routes/route66.css delete mode 100644 packages/cli/tests/subjects/preload-chunks/routes/route66.js delete mode 100644 packages/cli/tests/subjects/preload-chunks/routes/route89.css delete mode 100644 packages/cli/tests/subjects/preload-chunks/routes/route89.js delete mode 100644 packages/cli/tests/subjects/preload-chunks/style.css diff --git a/packages/cli/lib/commands/build.js b/packages/cli/lib/commands/build.js index 6722fe340..2fcfce27b 100644 --- a/packages/cli/lib/commands/build.js +++ b/packages/cli/lib/commands/build.js @@ -39,11 +39,6 @@ const options = [ name: '--template', description: 'Path to custom HTML template (default "src/template.html")', }, - { - name: '--preload', - description: 'Adds preload tags to the document its assets', - default: false, - }, { name: '--analyze', description: 'Launch interactive Analyzer to inspect production bundle(s)', diff --git a/packages/cli/lib/lib/webpack/create-load-manifest.js b/packages/cli/lib/lib/webpack/create-load-manifest.js deleted file mode 100644 index 948ee24d8..000000000 --- a/packages/cli/lib/lib/webpack/create-load-manifest.js +++ /dev/null @@ -1,68 +0,0 @@ -module.exports = (assets, namedChunkGroups, isProd) => { - if (!isProd) return {}; - /** - * This is a mapping of generic/pre-build filenames to their postbuild output - * - * bundle.js -> bundle.29bec.esm.js - * route-home.css -> styles/route-home.chunk.8aeee.css - * - * Even if a user alters the output name, we still have keys we can expect & rely on - */ - assets = JSON.parse(assets['asset-manifest.json']._value); - - const mainJs = assets['bundle.js']; - const mainCss = assets['bundle.css']; - - const defaults = { - ...(mainCss && { - [mainCss]: { - type: 'style', - weight: 1, - }, - }), - ...(mainJs && { - [mainJs]: { - type: 'script', - weight: 1, - }, - }), - }, - manifest = { - '/': defaults, - }; - - Object.keys(assets) - .filter(asset => /^route-.*\.js$/.test(asset)) - .map(asset => asset.replace(/\.js$/, '')) - .forEach(route => { - const routeManifest = Object.assign({}, defaults); - - const routeCss = assets[`${route}.css`]; - const routeJs = assets[`${route}.js`]; - - routeManifest[routeJs] = { type: 'script', weight: 0.9 }; - if (routeCss) routeManifest[routeCss] = { type: 'script', weight: 0.9 }; - - const path = route.replace(/^route-/, '/').replace(/^\/home/, '/'); - - if (namedChunkGroups) { - // async files to be loaded, generated by splitChunksPlugin - const asyncFiles = namedChunkGroups.get(route) || {}; - if (asyncFiles && asyncFiles.chunks) { - asyncFiles.chunks.forEach(asset => { - asset.files = asset.files || []; - asset.files.forEach(file => { - if (/\.css$/.test(file)) { - routeManifest[file] = { type: 'style', weight: 0.9 }; - } else if (/\.js$/.test(file)) { - routeManifest[file] = { type: 'script', weight: 0.9 }; - } - }); - }); - } - } - manifest[path] = routeManifest; - }); - - return manifest; -}; diff --git a/packages/cli/lib/lib/webpack/push-manifest.js b/packages/cli/lib/lib/webpack/push-manifest.js deleted file mode 100644 index 3f4e2c568..000000000 --- a/packages/cli/lib/lib/webpack/push-manifest.js +++ /dev/null @@ -1,28 +0,0 @@ -const { Compilation, sources } = require('webpack'); -const createLoadManifest = require('./create-load-manifest'); - -module.exports = class PushManifestPlugin { - constructor(isProd) { - this.isProd = isProd; - } - apply(compiler) { - compiler.hooks.thisCompilation.tap('PushManifestPlugin', compilation => { - compilation.hooks.processAssets.tap( - { - name: 'PushManifestPlugin', - stage: Compilation.PROCESS_ASSETS_STAGE_REPORT, - }, - () => { - const manifest = JSON.stringify( - createLoadManifest(compilation.assets, compilation.namedChunkGroups, this.isProd) - ); - - compilation.emitAsset( - 'push-manifest.json', - new sources.RawSource(manifest) - ); - } - ); - }); - } -}; diff --git a/packages/cli/lib/lib/webpack/render-html-plugin.js b/packages/cli/lib/lib/webpack/render-html-plugin.js index 9e9f589e1..9d1a9d12f 100644 --- a/packages/cli/lib/lib/webpack/render-html-plugin.js +++ b/packages/cli/lib/lib/webpack/render-html-plugin.js @@ -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 { esmImport, tryResolveConfig, warn } = require('../../util'); const PREACT_FALLBACK_URL = '/200.html'; @@ -82,14 +81,6 @@ 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, @@ -101,7 +92,6 @@ module.exports = async function renderHTMLPlugin(config) { preRenderData: values, CLI_DATA: { preRenderData: { url, ...routeData } }, ssr: config.prerender ? prerender({ cwd, dest, src }, values) : '', - loadManifest, entrypoints, }, htmlWebpackPlugin: { diff --git a/packages/cli/lib/lib/webpack/webpack-client-config.js b/packages/cli/lib/lib/webpack/webpack-client-config.js index 136c1f230..052defc24 100644 --- a/packages/cli/lib/lib/webpack/webpack-client-config.js +++ b/packages/cli/lib/lib/webpack/webpack-client-config.js @@ -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'); @@ -132,7 +131,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({ diff --git a/packages/cli/lib/resources/head-end.ejs b/packages/cli/lib/resources/head-end.ejs index 07ff50c69..63cf7b89c 100644 --- a/packages/cli/lib/resources/head-end.ejs +++ b/packages/cli/lib/resources/head-end.ejs @@ -2,10 +2,3 @@ <% if (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 `