-
Notifications
You must be signed in to change notification settings - Fork 87
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 automatic dependency management/externals generation to build process 🎉(fixes #1052) #1286
Conversation
Neither of these packages are used so we can stop including them everywhere. They can be added back in if we ever have need for them.
…script handle map.
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.
AWESOME STUFF
LOVE IT!!!
one suggestion I have to make things a bit more DRY would be to replace all of the repeated blocks of code in EventEspresso\core\domain\services\assets\CoreAssetManager
where the only thing changing is the asset handle.
For example, if we added a new method to EventEspresso\core\services\assets\AssetManager
that was maybe something like:
public function addStandardJavascript(
$handle,
array $extra_dependencies = array(),
$load_in_footer = true
) {
$dependencies = ! empty($extra_dependencies) && is_array($extra_dependencies)
? array_merge(
$this->registry->getJsDependencies(
$this->domain->assetNamespace(),
$handle
),
$extra_dependencies
)
: $this->registry->getJsDependencies(
$this->domain->assetNamespace(),
$handle
);
return $this->addJavascript(
$handle,
$this->registry->getJsUrl($this->domain->assetNamespace(), $handle),
$dependencies,
$load_in_footer
);
}
then the following code in CoreAssetManager::loadCoreJs()
:
$this->addJavascript(
CoreAssetManager::JS_HANDLE_JS_CORE,
$this->registry->getJsUrl($this->domain->assetNamespace(), CoreAssetManager::JS_HANDLE_JS_CORE),
$this->registry->getJsDependencies(
$this->domain->assetNamespace(),
CoreAssetManager::JS_HANDLE_JS_CORE
)
)
->setHasInlineData();
$this->addJavascript(
CoreAssetManager::JS_HANDLE_VENDOR,
$this->registry->getJsUrl($this->domain->assetNamespace(), CoreAssetManager::JS_HANDLE_VENDOR),
$this->registry->getJsDependencies(
$this->domain->assetNamespace(),
CoreAssetManager::JS_HANDLE_VENDOR
)
);
$this->addJavascript(
CoreAssetManager::JS_HANDLE_VALIDATORS,
$this->registry->getJsUrl($this->domain->assetNamespace(), CoreAssetManager::JS_HANDLE_VALIDATORS),
$this->registry->getJsDependencies(
$this->domain->assetNamespace(),
CoreAssetManager::JS_HANDLE_VALIDATORS
)
)->setRequiresTranslation();
$this->addJavascript(
CoreAssetManager::JS_HANDLE_HELPERS,
$this->registry->getJsUrl($this->domain->assetNamespace(), CoreAssetManager::JS_HANDLE_HELPERS),
$this->registry->getJsDependencies(
$this->domain->assetNamespace(),
CoreAssetManager::JS_HANDLE_HELPERS
)
)->setRequiresTranslation();
could be changed to something like:
$this->addStandardJavascript(CoreAssetManager::JS_HANDLE_JS_CORE)->setHasInlineData();
$this->addStandardJavascript(CoreAssetManager::JS_HANDLE_VENDOR);
$this->addStandardJavascript(CoreAssetManager::JS_HANDLE_VALIDATORS)->setRequiresTranslation();
$this->addStandardJavascript(CoreAssetManager::JS_HANDLE_HELPERS)->setRequiresTranslation();
since the only thing changing in those blocks of code is the asset handle, and what is done to the asset after it is registered.
I couldn't come up with a better name for addStandardJavascript()
(addAutoJavascript()
, addJavascriptByHandle()
???) but you might have a better idea.
Something similar could be done with the CSS assets
* This is a known array of possible wp css handles that correspond to what may be exposed as dependencies in our | ||
* build process. Currently the dependency export process in webpack does not consider css imports, so we derive | ||
* them via the js dependencies (WP uses the same handle for both js and css). This is a list of known handles that | ||
* are used for both js and css. |
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.
good description 👍
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.
looks great!!!
I gave this a priority of high because the longer this lingers the greater the chance of conflicts. Also, I'd like to merge this into the EDTR refactor work being done (which will already be a tricky merge). |
I tested the Event Attendees block and that worked: I also tested the exit modal with the skip option and then the yes option: |
…atic dependency management/externals generation to build process 🎉(fixes #1052) (#1286) * various changes/updates to webpack configs * Add dependency extraction webpack plugin * remove unused dependencies for react-redux and redux Neither of these packages are used so we can stop including them everywhere. They can be added back in if we ever have need for them. * dependency map extractor configuration for externals and external to script handle map. * update all depedency registrations * update build files (dev) * add back in changes removed in a bad rebase * make webpack config more dry. * update build files (dev) * remove unneccesary delete * fix typo (copy pasta) in webpack.prod.js * some more DRY work for asset manager * relocate wp css handles for dependency generation * add default return for condition where there isn’t a registered manifest file * remove unnecessary Domain injection * more implementations of asset helpers "
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.
Very cool to see this, hope it's working well 😁
@@ -0,0 +1,44 @@ | |||
const requestToExternal = ( request ) => { |
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.
😎
Hey! It's working very well! Thanks for creating the plugin. |
…cidental change of method scope (#1286) "
Problem this Pull Request solves
See #1052 for background. This pull will make php dependency management for scripts and styles, and js webpack configuration for externals much easier (and less prone to human error).
Two primary benefits introduced in this pull:
Dependencies for scripts and styles are automatically registered php side.
With a few exceptions, you'll never have to touch php again for any current registered scripts as it's all handled automatically. The exceptions are:
eventespresso-data-stores
. Since this is not imported in implementations, it doesn't get picked up by the dependency extraction. So there may be a few cases where it may need added as a dependency manually. However, in most cases (since it, itself is dependent onwp.data
) things should still get enqueued in the correct order.eventespresso-core-default-theme
will need to have that dependency added manually because it is not imported in any implementations (I have some ideas for improving this in future iterations, but its tricky so I'll leave out of this pull for now)Externals no longer need to be explicitly defined in the webpack config 🎉
Externals are picked up automatically via the dependency extraction webpack plugin (and the configuration for it). If any new packages are added they'll need to be updated in the configuration (I'll take care of doing this for the EDTR branch), but externals are automatically generated correctly for built files using the new webpack plugin.
To make all this possible, there were a number of corollary changes made in php files and js configuration including:
How has this been tested
This impacts all current released code using built files so:
EventAttendees
block works as expected.Checklist
esc_html__()
, see https://codex.wordpress.org/I18n_for_WordPress_Developers)