Skip to content

Commit

Permalink
Netlify CMS plugin: Don't use StaticQueryMapper
Browse files Browse the repository at this point in the history
The Netlify CMS plugin is spinning an extra webpack instance with almost
every plugin from gatsby. Reusing the `StaticQueryMapper` plugin caused
issues given how it's dealing with a Gatsby state.

Fixes gatsbyjs#29951

This commit also:
- removes `cssTests` which wasn't used anymore
- adds a clear TODO for how to get `excludeAssets` to be taken into account again
  • Loading branch information
ridem committed Mar 31, 2021
1 parent f628c38 commit cb49cec
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions packages/gatsby-plugin-netlify-cms/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ function deepMap(obj, fn) {
return obj
}

const cssTests = []

function replaceRule(value, stage) {
function replaceRule(value) {
// If `value` does not have a `test` property, it isn't a rule object.
if (!value || !value.test) {
return value
Expand Down Expand Up @@ -96,20 +94,6 @@ exports.onCreateWebpackConfig = (
return Promise.resolve()
}

// populate cssTests array later used by isCssRule
if (`develop` === stage) {
cssTests.push(
...[
rules.cssModules().test,
rules.css().test,
/\.s(a|c)ss$/,
/\.module\.s(a|c)ss$/,
/\.less$/,
/\.module\.less$/,
].map(t => t.toString())
)
}

const gatsbyConfig = getConfig()
const { program } = store.getState()
const publicPathClean = trim(publicPath, `/`)
Expand Down Expand Up @@ -161,15 +145,19 @@ exports.onCreateWebpackConfig = (
},
module: {
rules: deepMap(gatsbyConfig.module.rules, value =>
replaceRule(value, stage)
replaceRule(value)
).filter(Boolean),
},
plugins: [
// Remove plugins that either attempt to process the core Netlify CMS
// application, or that we want to replace with our own instance.
...gatsbyConfig.plugins.filter(
plugin =>
![`MiniCssExtractPlugin`, `GatsbyWebpackStatsExtractor`].find(
![
`MiniCssExtractPlugin`,
`GatsbyWebpackStatsExtractor`,
`StaticQueryMapper`,
].find(
pluginName =>
plugin.constructor && plugin.constructor.name === pluginName
)
Expand Down Expand Up @@ -210,7 +198,8 @@ exports.onCreateWebpackConfig = (
// Exclude CSS from index.html, as any imported styles are assumed to be
// targeting the editor preview pane. Uses `excludeAssets` option from
// `HtmlWebpackPlugin` config
// not compatible with webpack 5
// HtmlWebpackExcludeAssetsPlugin is not compatible with webpack 5
// TODO: Replace `html-webpack-exclude-assets-plugin` with `html-webpack-skip-assets-plugin`
// new HtmlWebpackExcludeAssetsPlugin(),

// Pass in needed Gatsby config values.
Expand Down

0 comments on commit cb49cec

Please sign in to comment.