1- const path = require ( `path` )
21const { onCreateWebpackConfig, onCreateBabelConfig } = require ( `../gatsby-node` )
32const PreactRefreshPlugin = require ( `@prefresh/webpack` )
43const ReactRefreshWebpackPlugin = require ( `@pmmmwh/react-refresh-webpack-plugin` )
54
5+ const FRAMEWORK_BUNDLES_GATSBY = [
6+ `react` ,
7+ `react-dom` ,
8+ `scheduler` ,
9+ `prop-types` ,
10+ ]
11+
12+ const FRAMEWORK_BUNDLES_REGEX_GATSBY = new RegExp (
13+ `(?<!node_modules.*)[\\\\/]node_modules[\\\\/](${ FRAMEWORK_BUNDLES_GATSBY . join (
14+ `|`
15+ ) } )[\\\\/]`
16+ )
17+
618describe ( `gatsby-plugin-preact` , ( ) => {
719 it ( `sets the correct webpack config in development` , ( ) => {
820 const getConfig = jest . fn ( ( ) => {
@@ -53,7 +65,6 @@ describe(`gatsby-plugin-preact`, () => {
5365 } )
5466
5567 it ( `sets the correct webpack config in production` , ( ) => {
56- const FRAMEWORK_BUNDLES = [ `react` , `react-dom` , `scheduler` , `prop-types` ]
5768 const getConfig = jest . fn ( ( ) => {
5869 return {
5970 optimization : {
@@ -65,14 +76,20 @@ describe(`gatsby-plugin-preact`, () => {
6576 framework : {
6677 chunks : `all` ,
6778 name : `framework` ,
68- // This regex ignores nested copies of framework libraries so they're bundled with their issuer.
69- test : new RegExp (
70- `(?<!node_modules.*)[\\\\/]node_modules[\\\\/](${ FRAMEWORK_BUNDLES . join (
71- `|`
72- ) } )[\\\\/]`
73- ) ,
79+ // Mirrors what we have in gatsby/../webpack.config.js
80+ test : module => {
81+ if (
82+ module ?. rawRequest === `react-dom/server` ||
83+ module ?. rawRequest ?. includes ( `/react-dom-server` )
84+ ) {
85+ return false
86+ }
87+
88+ return FRAMEWORK_BUNDLES_REGEX_GATSBY . test (
89+ module . nameForCondition ( )
90+ )
91+ } ,
7492 priority : 40 ,
75- // Don't let webpack eliminate this chunk (prevents this chunk from becoming a part of the commons chunk)
7693 enforce : true ,
7794 } ,
7895 } ,
@@ -121,7 +138,7 @@ describe(`gatsby-plugin-preact`, () => {
121138 "enforce": true,
122139 "name": "framework",
123140 "priority": 40,
124- "test": [Function] ,
141+ "test": /\\(\\?<!node_modules\\.\\*\\)\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]\\(preact\\|react\\|react-dom\\|scheduler\\|prop-types\\)\\[\\\\\\\\/\\]/ ,
125142 },
126143 "vendors": false,
127144 },
@@ -141,7 +158,7 @@ describe(`gatsby-plugin-preact`, () => {
141158 "enforce": true,
142159 "name": "framework",
143160 "priority": 40,
144- "test": /\\(\\?<!node_modules\\.\\*\\)\\[\\\\\\\\/\\]node_modules\\[\\\\\\\\/\\]\\(react\\|react-dom\\|scheduler\\|prop-types\\)\\[\\\\\\\\/\\]/ ,
161+ "test": [Function] ,
145162 },
146163 "vendors": false,
147164 },
0 commit comments