Skip to content

Commit

Permalink
refactor: use DefinePlugin instead of window.CMS_MANUAL_INIT
Browse files Browse the repository at this point in the history
  • Loading branch information
erezrokah committed Nov 26, 2019
1 parent 2b21bdb commit d2f44ff
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
1 change: 0 additions & 1 deletion packages/gatsby-plugin-netlify-cms/src/cms-manual-init.js

This file was deleted.

5 changes: 3 additions & 2 deletions packages/gatsby-plugin-netlify-cms/src/cms.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ import CMS from "netlify-cms-app"
/**
* Load Netlify CMS automatically if `window.CMS_MANUAL_INIT` is set.
*/
if (!window.CMS_MANUAL_INIT) {
// eslint-disable-next-line no-undef
if (!CMS_MANUAL_INIT) {
CMS.init()
} else {
console.log(
`\`window.CMS_MANUAL_INIT\` flag set, skipping automatic initialization.'`
`\`CMS_MANUAL_INIT\` flag set, skipping automatic initialization.'`
)
}

Expand Down
5 changes: 4 additions & 1 deletion packages/gatsby-plugin-netlify-cms/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ exports.onCreateWebpackConfig = (
...gatsbyConfig,
entry: {
cms: [
manualInit && path.join(__dirname, `cms-manual-init.js`),
path.join(__dirname, `cms.js`),
enableIdentityWidget && path.join(__dirname, `cms-identity.js`),
]
Expand Down Expand Up @@ -236,6 +235,10 @@ exports.onCreateWebpackConfig = (
tags: externals.map(({ assetName }) => assetName),
append: false,
}),

new webpack.DefinePlugin({
CMS_MANUAL_INIT: JSON.stringify(manualInit),
}),
].filter(p => p),

// Remove common chunks style optimizations from Gatsby's default
Expand Down

0 comments on commit d2f44ff

Please sign in to comment.