From 372d8fa7744b53398ee42cd910f7cb65dddcd480 Mon Sep 17 00:00:00 2001
From: Ryan Christian <33403762+rschristian@users.noreply.github.com>
Date: Thu, 18 Jan 2024 23:13:07 -0600
Subject: [PATCH] refactor: Remove `optimize-plugin` (#1816)
* refactor: Remove `optimize-plugin`
* test: Update test suite
* docs: Add changeset
---
.changeset/lazy-zoos-clean.md | 6 +
packages/cli/package.json | 1 -
.../cli/src/lib/webpack/render-html-plugin.js | 15 -
.../src/lib/webpack/webpack-client-config.js | 12 +-
packages/cli/src/resources/template.ejs | 2 -
packages/cli/tests/build.test.js | 56 ++-
packages/cli/tests/config-formats.test.js | 6 +-
packages/cli/tests/images/build.js | 31 +-
packages/cli/tests/lib/cli.js | 9 +-
packages/cli/tests/lib/utils.js | 41 ---
.../create-cli/src/resources/template.ejs | 2 -
yarn.lock | 332 +-----------------
12 files changed, 58 insertions(+), 455 deletions(-)
create mode 100644 .changeset/lazy-zoos-clean.md
diff --git a/.changeset/lazy-zoos-clean.md b/.changeset/lazy-zoos-clean.md
new file mode 100644
index 000000000..9d2368147
--- /dev/null
+++ b/.changeset/lazy-zoos-clean.md
@@ -0,0 +1,6 @@
+---
+'preact-cli': patch
+'create-preact-cli': patch
+---
+
+Removed `optimize-plugin`, now a single bundle will be output.
diff --git a/packages/cli/package.json b/packages/cli/package.json
index 842df00e2..71393c4d0 100644
--- a/packages/cli/package.json
+++ b/packages/cli/package.json
@@ -64,7 +64,6 @@
"kleur": "^4.1.4",
"mini-css-extract-plugin": "^2.5.3",
"minimatch": "^3.0.3",
- "optimize-plugin": "^1.3.1",
"postcss": "^8.4.13",
"postcss-load-config": "^3.1.4",
"postcss-loader": "^6.2.1",
diff --git a/packages/cli/src/lib/webpack/render-html-plugin.js b/packages/cli/src/lib/webpack/render-html-plugin.js
index 07bd497cd..93f916eb9 100644
--- a/packages/cli/src/lib/webpack/render-html-plugin.js
+++ b/packages/cli/src/lib/webpack/render-html-plugin.js
@@ -85,21 +85,6 @@ module.exports = async function renderHTMLPlugin(config, env) {
entrypoints[name] =
publicPath + entryFiles.find(file => /\.m?js(?:\?|$)/.test(file));
});
-
- const optimizePlugin = compilation.options.plugins.find(
- plugin => plugin.constructor.name == 'OptimizePlugin'
- );
- if (optimizePlugin) {
- // Retrieves the (generated) legacy bundle
- const legacyBundle = entrypoints['bundle']
- .replace(publicPath, '')
- .replace(/\.js$/, '.legacy.js');
- entrypoints['legacy-bundle'] = publicPath + legacyBundle;
-
- // Retrieves the (generated) es-polyfills
- entrypoints['es-polyfills'] =
- publicPath + optimizePlugin.options.polyfillsFilename;
- }
};
const htmlWebpackConfig = values => {
diff --git a/packages/cli/src/lib/webpack/webpack-client-config.js b/packages/cli/src/lib/webpack/webpack-client-config.js
index 3644ea0e0..622f60b18 100644
--- a/packages/cli/src/lib/webpack/webpack-client-config.js
+++ b/packages/cli/src/lib/webpack/webpack-client-config.js
@@ -14,7 +14,6 @@ const baseConfig = require('./webpack-base-config');
const { InjectManifest } = require('workbox-webpack-plugin');
const RefreshPlugin = require('@prefresh/webpack');
const { normalizePath, warn } = require('../../util');
-const OptimizePlugin = require('optimize-plugin');
const cleanFilename = name =>
name.replace(
@@ -46,7 +45,7 @@ async function clientConfig(config, env) {
swSrc: swPath,
include: [
/200\.html$/,
- /(?
- name.replace(/\.[a-z0-9]{5}((\.legacy)?\.(?:js|css)$)/i, '.*****$1'),
+ name.replace(/\.[a-z0-9]{5}(\.(?:js|css)$)/i, '.*****$1'),
}),
],
cache: true,
diff --git a/packages/cli/src/resources/template.ejs b/packages/cli/src/resources/template.ejs
index fce91cd13..fa5ebe5dc 100644
--- a/packages/cli/src/resources/template.ejs
+++ b/packages/cli/src/resources/template.ejs
@@ -21,7 +21,5 @@
<% } %>
-
-