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
Update/grunt to gulp: introduce js:uglify task #3647
Update/grunt to gulp: introduce js:uglify task #3647
Conversation
There were already some minified scripts included in the repository. I removed them to avoid maintaining a blacklist in the js:uglify Gulp task.
Repeating the same I would also recommend considering a few other factors in that check:
|
Thank you @jeherve . Do you think something like that could work? |
One potential issue here is that class.jetpack.php doesn't exist on WordPress.com. As a result, when we merge module files back to WordPress.com, every How about having no asset suffix by default, and add it if a specific filter is set to true? |
It's not entirely convenient to be able to debug a JS file only when |
@jeherve
@eliorivero For debugging purposes we could also add sourcemaps to the What do you think? |
Right, source maps are a convenient solution for debugging minified JS (dismiss the |
I've tried another approach leveraging the In this way the process is transparent: developers could use |
*/ | ||
$load_minified_scripts = apply_filters( 'jetpack_load_minified_scripts', $load_minified_scripts ); | ||
|
||
if ( false !== strpos( $src, $jetpack_url ) && $load_minified_scripts ) { |
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 block feels pretty brittle, and prone to problems (especially if there are files along the lines of core.jsdom.js
or something that has .js
in amongst it.
You might need to parse the URLs a bit deeper and look at the basename
, then regex or whatever to see that specifically the last 3 characters are .js
.
Instead of simply replacing every `.js` that is present in the file name, check just for the last three characters.
I have updated the code to reflect @beaulebens suggestions and added some more unit tests. |
$load_minified_scripts = apply_filters( 'jetpack_load_minified_scripts', $load_minified_scripts ); | ||
|
||
if ( false !== strpos( $src, $jetpack_url ) && $load_minified_scripts ) { | ||
$file_name = basename( parse_url( $src, PHP_URL_PATH ) ); |
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.
need to strtolower()
just in case?
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.
Or on the line below (just for the comparison) to avoid "changing" the filename for case-sensitive OSes.
The net result of the pull request was showing a lot of modified files, the only changes being the replacement of single quotes with double quotes, that were used for string interpolation.
There was already a method used to minify assets. So it's better to merge the two and keep functionality in one place
The existing test for Jetpack assets would ignore files from the `_inc` folder and hardcoded Jetpack folder name.
$file = "{$base}/{$path}"; | ||
$full_path = JETPACK__PLUGIN_DIR . substr( $file, 8 ); | ||
$full_path = JETPACK__PLUGIN_DIR . substr( $file, strlen( basename( JETPACK__PLUGIN_DIR ) ) + 1 ); |
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.
👍
Closing since we're already using uglify in Gulp |
Fixes #3487 .
Changes proposed in this Pull Request:
js:uglify
task to minify all .js files.SCRIPT_DEBUG
isn't defined or is false.grunt jshint
before to commit your changes. It will allow you to detect errors in Javascript files.