Add a public bundledPackages
/excludedExternals
option to DEWP
#45948
+93
−7
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.
What?
This PR allows users of the Dependency Extraction Webpack Plugin "do a simple thing easy" (and complex things still possible) and exclude packages from externalizing in a simple way. It also upstream WooCommerceDEWP feature (woocommerce/woocommerce-admin#7034). Or, in other words, publish the private feature of
BUNDLED_PACKAGES
.It also includes a tiny clarification in the README (e8f3e85). The example was using the
entrypoint
for the assets file, whereas the plugin usesoutput
config for that. (fixes #49872)Why?
requestToExternal
is used to filter a list of packages.WooCommerceDependencyExtractionWebpackPlugin
'sbundledPackages
not working for@wordpress/
packages.How?
This PR changes the DEWP constructor to take
excludedExternals
option to use it to filter packages processed inexternalizeWpDeps
before anyrequestToExternal
is called.Turns the old
BUNDLED_PACKAGES
to the option's default value and exposes it as a static property to allow extending it by consumers.Testing Instructions
Run automated tests
npx wp-scripts test-unit-js --config test/unit/jest.config.js packages/dependency-extraction-webpack-plugin/
Manual testing
@wordpress/components
,@wordpress/url
,@wordpress/icons
and@wordpress/interface
@wordpress/url
,@wordpress/icons
and@wordpress/interface
gets bundled, and none of them is logged.Screenshots or screencast
Additional info:
bundledPackages
name. This would keep the old name, and make it directly compatible with existing WooCommerce implementation. However:options.requestToExternal
, so this way we avoid breaking change./icons
and/interface
are bundled, but didn't manage for test build to process it. I guess it's related to the monorepo setup. Forlodash
it works as expected.cc @gziolo as you reviewed my latest DEWP related issues
cc @louwie17 as someone who implemented it in Woo, and could give a context about why it eventually landed as
bundledPackages
notexcludedExternals
.