From 66bd9c9e5cf67e69382d7e5047e43254c992f187 Mon Sep 17 00:00:00 2001 From: LekoArts Date: Wed, 15 Feb 2023 09:17:59 +0100 Subject: [PATCH] fix --- .../src/__tests__/gatsby-node.js | 39 +++++++++++++------ .../gatsby-plugin-preact/src/gatsby-node.js | 23 +++++++---- packages/gatsby/src/utils/webpack.config.js | 1 + 3 files changed, 45 insertions(+), 18 deletions(-) diff --git a/packages/gatsby-plugin-preact/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-preact/src/__tests__/gatsby-node.js index 3ab7bd41fea84..61707a32095bc 100644 --- a/packages/gatsby-plugin-preact/src/__tests__/gatsby-node.js +++ b/packages/gatsby-plugin-preact/src/__tests__/gatsby-node.js @@ -1,8 +1,20 @@ -const path = require(`path`) const { onCreateWebpackConfig, onCreateBabelConfig } = require(`../gatsby-node`) const PreactRefreshPlugin = require(`@prefresh/webpack`) const ReactRefreshWebpackPlugin = require(`@pmmmwh/react-refresh-webpack-plugin`) +const FRAMEWORK_BUNDLES_GATSBY = [ + `react`, + `react-dom`, + `scheduler`, + `prop-types`, +] + +const FRAMEWORK_BUNDLES_REGEX_GATSBY = new RegExp( + `(? { it(`sets the correct webpack config in development`, () => { const getConfig = jest.fn(() => { @@ -53,7 +65,6 @@ describe(`gatsby-plugin-preact`, () => { }) it(`sets the correct webpack config in production`, () => { - const FRAMEWORK_BUNDLES = [`react`, `react-dom`, `scheduler`, `prop-types`] const getConfig = jest.fn(() => { return { optimization: { @@ -65,14 +76,20 @@ describe(`gatsby-plugin-preact`, () => { framework: { chunks: `all`, name: `framework`, - // This regex ignores nested copies of framework libraries so they're bundled with their issuer. - test: new RegExp( - `(? { + if ( + module?.rawRequest === `react-dom/server` || + module?.rawRequest?.includes(`/react-dom-server`) + ) { + return false + } + + return FRAMEWORK_BUNDLES_REGEX_GATSBY.test( + module.nameForCondition() + ) + }, priority: 40, - // Don't let webpack eliminate this chunk (prevents this chunk from becoming a part of the commons chunk) enforce: true, }, }, @@ -121,7 +138,7 @@ describe(`gatsby-plugin-preact`, () => { "enforce": true, "name": "framework", "priority": 40, - "test": [Function], + "test": /\\(\\? { "enforce": true, "name": "framework", "priority": 40, - "test": /\\(\\? - /(? { // Packages like gatsby-plugin-image might import from "react-dom/server". We don't want to include react-dom-server in the framework bundle. // A rawRequest might look like these: