-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unminified source JS files to builds #1643
Add unminified source JS files to builds #1643
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
$detection_script_file = 'detect.min.js'; | ||
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { | ||
$detection_script_file = 'detect.js'; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to reuse wp_scripts_get_suffix()
here as seen in wp_default_scripts()
in core:
$detection_script_file = 'detect.min.js'; | |
if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) { | |
$detection_script_file = 'detect.js'; | |
} | |
$detection_script_file = sprintf( 'detect%s.js', wp_scripts_get_suffix() ); |
I was thinking alternatively that we could load the |
Oh, there are also now 3 other JS files that need to have their minified version included conditionally:
|
@@ -164,6 +168,7 @@ const buildPlugin = ( env ) => { | |||
{ | |||
from, | |||
to, | |||
info: { minimized: true }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This won't attempt to create a minified version of web-vitals.js
, will it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, actually it's the opposite - setting info: { minimized: true }
tells Webpack to skip running these files through the minimizer. It's a way to tell Webpack to copy the files 'as is' without trying to minimize them. The documentation specifically mentions this is 'Useful if you need to simply copy *.js files to destination "as is" without evaluating and minimizing them using Terser.'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thank you. I'm a little confused. We want to create minified versions of all the scripts, except for those which are copied from node_modules
, right? So we'd want to copy from node_modules/web-vitals/dist
and node_modules/@builder.io/partytown
as pre-minified, but everything else we'd want to create minified versions for. I don't see how that is all configured here. (I'm a webpack novice!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me clarify the current state and what needs to be fixed:
-
For files from
node_modules
(web-vitals
andpartytown
):- These come pre-minified, but when copying them to the
build
directory for their respective plugins, we're not telling Webpack that. Currently, I have configured minimization skipping only for the production build. - Need to add
info: { minimized: true }
to prevent re-minification attempts
- These come pre-minified, but when copying them to the
-
For plugin JS files that need minified versions:
- Minified version for
optimization-detective/detect.js
is being created (detect.min.js
) - Need to add minified versions for (I missed these as they were not initially part of the issue description):
embed-optimizer/detect.js
embed-optimizer/lazy-load.js
image-prioritizer/lazy-load.js
- Minified version for
I'll update this PR to handle both these cases. Would that address your concerns?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I believe so!
@@ -61,16 +61,20 @@ const optimizationDetective = ( env ) => { | |||
patterns: [ | |||
{ | |||
from: `${ source }/dist/web-vitals.js`, | |||
to: `${ destination }/web-vitals.js`, | |||
to: `${ destination }/build/web-vitals.js`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this missing the flag to say it is minified?
to: `${ destination }/build/web-vitals.js`, | |
to: `${ destination }/build/web-vitals.js`, | |
info: { minimized: true }`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! I just realized this. I should probably make this change in the config for Web Worker Offloading as well, which is copying the partytown files.
@@ -164,6 +168,7 @@ const buildPlugin = ( env ) => { | |||
{ | |||
from, | |||
to, | |||
info: { minimized: true }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, thank you. I'm a little confused. We want to create minified versions of all the scripts, except for those which are copied from node_modules
, right? So we'd want to copy from node_modules/web-vitals/dist
and node_modules/@builder.io/partytown
as pre-minified, but everything else we'd want to create minified versions for. I don't see how that is all configured here. (I'm a webpack novice!)
…ed Optimizer plugin
…ge Prioritizer plugin
I wanted to bring up something I noticed regarding the partytown package used in the web worker offloading plugin:
Since the partytown code is inlined as a script tag, should I modify this plugin to use the unminified partytown JavaScript when |
@ShyamGadde definitely! The non-minified debug version should be used here when
|
And good catch on the config erroneously minifying the debug scripts: https://plugins.trac.wordpress.org/browser/web-worker-offloading/tags/0.1.1/build/partytown-atomics.js The second one shouldn't have been minified! |
Co-authored-by: Weston Ruter <westonruter@google.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! It's everything I ever dreamed for!
Summary
Fixes #1493
Relevant technical choices
web-vitals.js
is not included because the file is copied directly from the pre-minified version innode_modules
.SCRIPT_DEBUG
is enabled.