-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gatsby-plugin-preact): enable preact in development (#22441)
Co-authored-by: Ward Peeters <ward@coding-tech.com>
- Loading branch information
1 parent
0558443
commit ca19076
Showing
5 changed files
with
27 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
// TODO enable preact/debug again when preact devtools is fixed. | ||
// exports.onClientEntry = () => { | ||
// if (process.env.NODE_ENV !== `production`) { | ||
// require(`preact/debug`) | ||
// } | ||
// } | ||
exports.onClientEntry = () => { | ||
if (process.env.NODE_ENV !== `production`) { | ||
console.log(`[HMR] disabled: preact is not compatible with RHL`) | ||
require(`preact/debug`) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
exports.onCreateWebpackConfig = ({ stage, actions }) => { | ||
// Requiring the server version of React-dom is hardcoded right now | ||
// in the development server. So we'll just avoid loading Preact there | ||
// for now. | ||
if (stage !== `develop`) { | ||
actions.setWebpackConfig({ | ||
resolve: { | ||
alias: { | ||
react: `preact/compat`, | ||
"react-dom": `preact/compat`, | ||
"react-dom/server": `preact/compat`, | ||
}, | ||
exports.onPreInit = () => { | ||
// Setting this variable replaces react-hot-loader with | ||
// [fast-refresh](https://reactnative.dev/docs/next/fast-refresh) | ||
// and resolves conflicts with running Preact in development. | ||
process.env.GATSBY_HOT_LOADER = `fast-refresh` | ||
} | ||
|
||
exports.onCreateWebpackConfig = ({ actions }) => { | ||
// React-dom is hardcoded as part of react-hot-loader | ||
// in the development server. So we either avoid Preact | ||
// during development or switch to fast-refresh and loose | ||
// hot reloading capabilities. | ||
actions.setWebpackConfig({ | ||
resolve: { | ||
alias: { | ||
react: `preact/compat`, | ||
"react-dom": `preact/compat`, | ||
"react-dom/server": `preact/compat`, | ||
}, | ||
}) | ||
} | ||
}, | ||
}) | ||
} |