From d31645c10352363f1af509a11ad633604be3f40e Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Mon, 13 Sep 2021 18:27:35 +0200 Subject: [PATCH] chore(gatsby): add webpack file to export same version (#33126) * chore(gatsby): add webpack export * add patch file to move to gatsby/webpack --- .../src/gatsby-node.js | 11 ++-- packages/gatsby/webpack.d.ts | 3 + packages/gatsby/webpack.js | 3 + .../5-plugins-use-webpack-from-gatsby.patch | 58 +++++++++++++++++++ 4 files changed, 68 insertions(+), 7 deletions(-) create mode 100644 packages/gatsby/webpack.d.ts create mode 100644 packages/gatsby/webpack.js create mode 100644 patches/v4/5-plugins-use-webpack-from-gatsby.patch diff --git a/packages/gatsby-plugin-netlify-cms/src/gatsby-node.js b/packages/gatsby-plugin-netlify-cms/src/gatsby-node.js index 3f060702bb493..634e2775fbe80 100644 --- a/packages/gatsby-plugin-netlify-cms/src/gatsby-node.js +++ b/packages/gatsby-plugin-netlify-cms/src/gatsby-node.js @@ -200,9 +200,11 @@ exports.onCreateWebpackConfig = ( }), // Pass in needed Gatsby config values. - new webpack.DefinePlugin({ + plugins.define({ __PATH__PREFIX__: pathPrefix, CMS_PUBLIC_PATH: JSON.stringify(publicPath), + CMS_MANUAL_INIT: JSON.stringify(manualInit), + PRODUCTION: JSON.stringify(stage !== `develop`), }), new CopyPlugin({ @@ -225,11 +227,6 @@ exports.onCreateWebpackConfig = ( tags: externals.map(({ assetName }) => assetName), append: false, }), - - new webpack.DefinePlugin({ - CMS_MANUAL_INIT: JSON.stringify(manualInit), - PRODUCTION: JSON.stringify(stage !== `develop`), - }), ].filter(p => p), // Remove common chunks style optimizations from Gatsby's default @@ -281,7 +278,7 @@ exports.onCreateWebpackConfig = ( plugins: enableIdentityWidget ? [] : [ - new webpack.IgnorePlugin({ + plugins.ignore({ resourceRegExp: /^netlify-identity-widget$/, }), ], diff --git a/packages/gatsby/webpack.d.ts b/packages/gatsby/webpack.d.ts new file mode 100644 index 0000000000000..accceacfeac78 --- /dev/null +++ b/packages/gatsby/webpack.d.ts @@ -0,0 +1,3 @@ +import webpack from "webpack" + +export = webpack diff --git a/packages/gatsby/webpack.js b/packages/gatsby/webpack.js new file mode 100644 index 0000000000000..5d0712f270ada --- /dev/null +++ b/packages/gatsby/webpack.js @@ -0,0 +1,3 @@ +"use strict" + +module.exports = require('webpack'); diff --git a/patches/v4/5-plugins-use-webpack-from-gatsby.patch b/patches/v4/5-plugins-use-webpack-from-gatsby.patch new file mode 100644 index 0000000000000..8b2151556e88c --- /dev/null +++ b/patches/v4/5-plugins-use-webpack-from-gatsby.patch @@ -0,0 +1,58 @@ +diff --git a/packages/gatsby-plugin-mdx/package.json b/packages/gatsby-plugin-mdx/package.json +index 4fa83e356f..4e18ac3fa0 100644 +--- a/packages/gatsby-plugin-mdx/package.json ++++ b/packages/gatsby-plugin-mdx/package.json +@@ -14,6 +14,7 @@ + "directory": "packages/gatsby-plugin-mdx" + }, + "peerDependencies": { ++ "gatsby": "^4.0.0-alpha-9689ff", + "@mdx-js/mdx": "^1.0.0", + "@mdx-js/react": "^1.0.0", + "react": "^16.9.0 || ^17.0.0", +diff --git a/packages/gatsby-plugin-mdx/utils/render-html.js b/packages/gatsby-plugin-mdx/utils/render-html.js +index 16d1080b21..ab390241b3 100644 +--- a/packages/gatsby-plugin-mdx/utils/render-html.js ++++ b/packages/gatsby-plugin-mdx/utils/render-html.js +@@ -1,4 +1,4 @@ +-const webpack = require(`webpack`) ++const webpack = require(`gatsby/webpack`) + const path = require(`path`) + const evaluate = require(`eval`) + const debug = require(`debug`)(`gatsby-plugin-mdx:render-html`) +diff --git a/packages/gatsby-plugin-netlify-cms/package.json b/packages/gatsby-plugin-netlify-cms/package.json +index cdd3644243..c84c97d074 100644 +--- a/packages/gatsby-plugin-netlify-cms/package.json ++++ b/packages/gatsby-plugin-netlify-cms/package.json +@@ -15,8 +15,7 @@ + "html-webpack-tags-plugin": "^3.0.1", + "lodash": "^4.17.21", + "mini-css-extract-plugin": "1.6.2", +- "netlify-identity-widget": "^1.9.2", +- "webpack": "^5.35.0" ++ "netlify-identity-widget": "^1.9.2" + }, + "devDependencies": { + "@babel/cli": "^7.15.4", +@@ -40,7 +39,8 @@ + "gatsby": "^4.0.0-alpha-9689ff", + "netlify-cms-app": "^2.9.0", + "react": "^16.9.0 || ^17.0.0", +- "react-dom": "^16.9.0 || ^17.0.0" ++ "react-dom": "^16.9.0 || ^17.0.0", ++ "webpack": "^5.0.0" + }, + "repository": { + "type": "git", +diff --git a/packages/gatsby-plugin-netlify-cms/src/gatsby-node.js b/packages/gatsby-plugin-netlify-cms/src/gatsby-node.js +index 3f060702bb..bb04a2a389 100644 +--- a/packages/gatsby-plugin-netlify-cms/src/gatsby-node.js ++++ b/packages/gatsby-plugin-netlify-cms/src/gatsby-node.js +@@ -1,6 +1,6 @@ + import path from "path" + import { mapValues, isPlainObject, trim } from "lodash" +-import webpack from "webpack" ++import webpack from "gatsby/webpack" + import HtmlWebpackPlugin from "html-webpack-plugin" + import { HtmlWebpackSkipAssetsPlugin } from "html-webpack-skip-assets-plugin" + import MiniCssExtractPlugin from "mini-css-extract-plugin"