This repository has been archived by the owner on Jul 28, 2023. It is now read-only.
Add preact/debug tools to development version of bundle #222
+105
−60
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See discussion #219
This PR adds the preact debug tools to the runtime. Webpack now creates two versions of the runtime. A
runtime.js
including the debugtools and aruntime.min.js
without them. Bundle size is nearly the same.If
SCRIPT_DEBUG
is set to true, the plugin enqueues the version with debug tools. Both versions are minified.To make it work I had to extend the webpack config and return multiple configs - that's why common config is stored in a shared config. Also the
DefinePlugin
is used to build a constant which can be checked in the runtime on whether to import the debug tools or note.preact/debug
cannot be externalized and needs to be the first import, that's why a flag is used.I'm not a webpack expert, so if there's a better way to do it let me know.
How to test:
npm build
.wp-env.json
setconfig
.SCRIPT_DEBUG
totrue
wp-env start
.runtime.js
was loaded. Preact devtools should be enabled (and not show a warning about missing renderings). Preact devtools should show some directives..wp-env.json
setconfig
.SCRIPT_DEBUG
tofalse
wp-env start
.runtime.min.js
was loaded. Preact devtools should not be enabled/active or show a warning about missing renderings.