Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Add babel-plugin-transform-remove-prop-types Babel plugin #839

Merged
merged 3 commits into from Aug 13, 2019

Conversation

nerrad
Copy link
Contributor

@nerrad nerrad commented Aug 12, 2019

This babel plugin will remove prop-types from production builds (prop-types remain in developer builds) bringing some file size savings. The file-size savings are minimal but could add up over time.

Changes in file size on production builds:

File Name Before After
blocks.js 7.89KiB 7.83KiB
editor.js 77b 77
featured-category.js 18.7 KiB 18.3
handpicked-products.js 23.7 KiB 23
product-best-sellers.js 15KiB 14.3
product-categories.js 17.3 KiB 17.2
product-category.js 19.7 KiB 18.9
product-new.js 20.5 KiB 19.7
product-on-sale.js 16.2 KiB 15.4
product-search.js 6.51 KiB 6.39
product-tag.js 18.5 KiB 17.7
product-top-rated.js 14.9 KiB 14.2
products-by-attribute.js 19.3 KiB 18.5
frontend.js 8.93KiB 8.93

How to test the changes in this Pull Request:

This affects any production builds because the plugin does remove any prop-type definitions. So there should be a run through of each block type inserted/edited in posts to ensure there's no console errors. Any issues should surface immediately as they would typically be syntax type errors.

Changelog

Enhancement: Remove prop-type implemention on release builds to reduce bundle size.

@nerrad nerrad added tools Used for work on build or release tools. type: enhancement The issue is a request for an enhancement. labels Aug 12, 2019
@nerrad nerrad marked this pull request as ready for review August 12, 2019 16:53
@nerrad nerrad requested a review from a team August 12, 2019 16:53
@nerrad nerrad self-assigned this Aug 12, 2019
Copy link
Contributor

@Aljullu Aljullu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and everything seems to work fine: all blocks load without problems and an error is still raised when props are invalid.

@@ -105,7 +105,10 @@ const GutenbergBlocksConfig = {
use: {
loader: 'babel-loader?cacheDirectory',
options: {
presets: [ '@wordpress/default' ],
presets: [ '@wordpress/babel-preset-default' ],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit confused with this. In @wordpress/babel-preset-default docs it recommends using "presets": [ "@wordpress/default" ].

Copy link
Contributor Author

@nerrad nerrad Aug 13, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm ya, essentially I just noticed that the full form was being used everywhere in Gutenberg (but not that the docs were just recommending the shorthand). Incidentally, I asked about this in #core-editor slack and I learned about shorthands for presets - which I didn't know about.

So the original was sufficient. However, I'd prefer the longform because imo it's a bit clearer what package is providing the preset. Happy to change back though?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't know about this either. Thanks for posting the explanation!

So the original was sufficient. However, I'd prefer the longform because imo it's a bit clearer what package is providing the preset. Happy to change back though?

Agree, let's keep the long name.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
tools Used for work on build or release tools. type: enhancement The issue is a request for an enhancement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants