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 @@ <% } %> - - diff --git a/packages/cli/tests/build.test.js b/packages/cli/tests/build.test.js index 3fd72fdef..e85ebb08c 100644 --- a/packages/cli/tests/build.test.js +++ b/packages/cli/tests/build.test.js @@ -8,7 +8,7 @@ const { writeFile, } = require('fs/promises'); const looksLike = require('html-looks-like'); -const { create, build, buildFast } = require('./lib/cli'); +const { create, build } = require('./lib/cli'); const { snapshot } = require('./lib/utils'); const { subject } = require('./lib/output'); const images = require('./images/build'); @@ -80,25 +80,25 @@ describe('preact build', () => { it('builds the `typescript` template', async () => { let dir = await create('typescript'); - await expect(buildFast(dir)).resolves.not.toThrow(); + await expect(build(dir)).resolves.not.toThrow(); }); it('should patch global location object', async () => { let dir = await subject('location-patch'); - await expect(buildFast(dir)).resolves.not.toThrow(); + await expect(build(dir)).resolves.not.toThrow(); }); it('should copy resources from static to build directory', async () => { let dir = await subject('static-root'); - await buildFast(dir); + await build(dir); let file = join(dir, 'build', '.htaccess'); expect(await access(file)).toBeUndefined(); }); it('should use a custom `.env` with prefixed environment variables', async () => { let dir = await subject('custom-dotenv'); - await buildFast(dir); + await build(dir); const bundleFile = (await readdir(`${dir}/build`)).find(file => /bundle\.\w{5}\.js$/.test(file) @@ -131,15 +131,13 @@ describe('preact build', () => { await rename(join(dir, 'index.js'), join(dir, 'renamed-src/index.js')); await rename(join(dir, 'style.css'), join(dir, 'renamed-src/style.css')); - await expect( - buildFast(dir, { src: 'renamed-src' }) - ).resolves.not.toThrow(); + await expect(build(dir, { src: 'renamed-src' })).resolves.not.toThrow(); }); it('--dest', async () => { let dir = await subject('minimal'); - await buildFast(dir, { dest: 'renamed-dest' }); + await build(dir, { dest: 'renamed-dest' }); expect(await access(join(dir, 'renamed-dest'))).toBeUndefined(); }); @@ -148,13 +146,13 @@ describe('preact build', () => { const logSpy = jest.spyOn(process.stdout, 'write'); - await buildFast(dir, { sw: true }); + await build(dir, { sw: true }); expect(await access(join(dir, 'build', 'sw.js'))).toBeUndefined(); expect(logSpy).toHaveBeenCalledWith( expect.stringContaining('Could not find sw.js') ); - await buildFast(dir, { sw: false }); + await build(dir, { sw: false }); await expect(access(join(dir, 'build', 'sw.js'))).rejects.toThrow( 'no such file or directory' ); @@ -165,12 +163,12 @@ describe('preact build', () => { // Prerendering is disabled to avoid (non-relevant) regenerator issues let dir = await subject('custom-babelrc'); - await buildFast(dir, { prerender: false }); + await build(dir, { prerender: false }); let transpiledChunk = await getOutputFile(dir, /bundle\.\w{5}\.js$/); expect(/=>\s?setTimeout/.test(transpiledChunk)).toBe(false); await rename(join(dir, '.babelrc'), join(dir, 'babel.config.json')); - await buildFast(dir, { + await build(dir, { babelConfig: 'babel.config.json', prerender: false, }); @@ -185,7 +183,7 @@ describe('preact build', () => { join(dir, 'template.ejs'), join(dir, 'renamed-template.ejs') ); - await buildFast(dir, { template: 'renamed-template.ejs' }); + await build(dir, { template: 'renamed-template.ejs' }); const html = await getOutputFile(dir, 'index.html'); expect(html).toEqual( @@ -196,11 +194,11 @@ describe('preact build', () => { it('--prerender', async () => { let dir = await subject('minimal'); - await buildFast(dir, { prerender: true }); + await build(dir, { prerender: true }); let html = await getOutputFile(dir, 'index.html'); expect(html).toMatch('

Minimal App

'); - await buildFast(dir, { prerender: false }); + await build(dir, { prerender: false }); html = await getOutputFile(dir, 'index.html'); expect(html).not.toMatch('

Minimal App

'); }); @@ -208,7 +206,7 @@ describe('preact build', () => { it('--prerenderUrls', async () => { let dir = await subject('multiple-prerendering'); - await buildFast(dir, { prerenderUrls: 'prerender-urls.json' }); + await build(dir, { prerenderUrls: 'prerender-urls.json' }); expect(await access(join(dir, 'build/index.html'))).toBeUndefined(); expect( await access(join(dir, 'build/route66/index.html')) @@ -221,7 +219,7 @@ describe('preact build', () => { join(dir, 'prerender-urls.json'), join(dir, 'renamed-urls.json') ); - await buildFast(dir, { prerenderUrls: 'renamed-urls.json' }); + await build(dir, { prerenderUrls: 'renamed-urls.json' }); expect(await access(join(dir, 'build/index.html'))).toBeUndefined(); expect( await access(join(dir, 'build/route66/index.html')) @@ -234,11 +232,11 @@ describe('preact build', () => { it('--inlineCss', async () => { let dir = await subject('minimal'); - await buildFast(dir, { inlineCss: true }); + await build(dir, { inlineCss: true }); let head = await getHead(dir); expect(head).toMatch(''); - await buildFast(dir, { inlineCss: false }); + await build(dir, { inlineCss: false }); head = await getOutputFile(dir, 'index.html'); expect(head).not.toMatch(/