Skip to content
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 the documentation of wp scripts #14499

Closed
wants to merge 1 commit into from

Conversation

Jackie6
Copy link
Contributor

@Jackie6 Jackie6 commented Mar 18, 2019

Description

Fix #14492

How has this been tested?

  • Local

Types of changes

Update the documentation of wp scripts. Specifically, add the following options to wp-scripts build and remove some redundant comments in webpack.config.js.
WP_BUNDLE_ANALYZER
WP_DEVTOOL
WP_LIVE_RELOAD_PORT

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.

@@ -54,6 +54,12 @@ This is how you execute the script with presented setup:

* `npm run build` - builds the code for production.

_Options_:

- `--WP_BUNDLE_ANALYZER` : This flag is used to enables utility that represents bundle content as convenient interactive zoomable treemap.
Copy link
Member

Choose a reason for hiding this comment

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

As I understand it, these are interpreted by the wp scripts script as environment variables, not as options flags.

In other words, instead of:

wp scripts build --WP_BUNDLE_ANALYZER

I think the correct usage is...

WP_BUNDLE_ANALYZER=true wp scripts

Please correct me if I'm mistaken.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi! Thanks for comments!
I am not sure which way is correct to use --WP_BUNDLE_ANALYZER. But for the WP_LIVE_RELOAD_PORT, I have tried npm run build --WP_LIVE_RELOAD_PORT=12345 and npm run build WP_LIVE_RELOAD_PORT=12345. The first one works but the second one fails and the error message is

Insufficient number of arguments or no entry found. Alternatively, run 'webpack(-cli) --help' for usage info.

According to the documentation of Environment Variables and Environment Options in web pack, I think we can use the double hyphen to specify the variables including WP_BUNDLE_ANALYZER, WP_BUNDLE_ANALYZER and WP_DEVTOOL.

Copy link
Member

Choose a reason for hiding this comment

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

@aduth is correct, they should be rather provided before the command. Unless we replicate what @draganescu did for e2e tests and introduce new CLI args, convert them to env variables in node and filter them out before passing to webpack.

@gziolo gziolo requested a review from draganescu March 19, 2019 12:12
@gziolo gziolo added [Type] Developer Documentation Documentation for developers [Type] Build Tooling Issues or PRs related to build tooling labels Mar 19, 2019
@@ -96,11 +96,7 @@ const config = {
],
},
plugins: [
// WP_BUNDLE_ANALYZER global variable enables utility that represents bundle content
Copy link
Member

Choose a reason for hiding this comment

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

These inline comments should stay here.


- `--WP_BUNDLE_ANALYZER` : This flag is used to enables utility that represents bundle content as convenient interactive zoomable treemap.
- `--WP_LIVE_RELOAD_PORT` : When present, the port on which live reload works when running watch mode will be changed. An example usage would be `npx wp-scripts build --WP_LIVE_RELOAD_PORT=1234`.
- `--WP_DEVTOOL` : A development tool is designated to control how source maps are generated. More information can be found [here](https://webpack.js.org/configuration/devtool/#devtool).
Copy link
Member

Choose a reason for hiding this comment

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

Both WP_DEVTOOL and WP_LIVE_RELOAD_PORT get only applied in development mode - this means it works only with start script.

@@ -54,6 +54,12 @@ This is how you execute the script with presented setup:

* `npm run build` - builds the code for production.

_Options_:

- `--WP_BUNDLE_ANALYZER` : This flag is used to enables utility that represents bundle content as convenient interactive zoomable treemap.
Copy link
Member

Choose a reason for hiding this comment

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

@aduth is correct, they should be rather provided before the command. Unless we replicate what @draganescu did for e2e tests and introduce new CLI args, convert them to env variables in node and filter them out before passing to webpack.

Copy link
Member

@oandregal oandregal left a comment

Choose a reason for hiding this comment

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

Thanks for the time invested in this proposal.

As per conversation in the core-js meetings, the consensus is to explore how plugins/themes can extend the default webpack config. That's something we haven't considered yet AFAIK, and this method may not be the one we end up implementing (or perhaps it is! I don't know). I worry that if we make it public now, we'll be tied to this, so until we have time to revisit how to better extend the webpack defaults, I'd rather not document these internal things.

@gziolo
Copy link
Member

gziolo commented Mar 20, 2019

As per conversation in the core-js meetings, the consensus is to explore how plugins/themes can extend the default webpack config.

This is something that is already supported by wp-scripts so I don't see any reason why we should keep it secret. It doesn't require any work in the config file itself. We only would need to prefix those CLI args with --webpack- so we could stop supporting them as soon as we migrate to a different tool.

@gziolo
Copy link
Member

gziolo commented Apr 10, 2019

@Jackie6 do you plan to address feedback shared?

@gziolo
Copy link
Member

gziolo commented Apr 10, 2019

There is a similar logic implemented for wp-scripts test-e2e:

https://github.com/WordPress/gutenberg/blob/master/packages/scripts/scripts/test-e2e.js#L46-L65

@Jackie6
Copy link
Contributor Author

Jackie6 commented Apr 11, 2019

@gziolo Hey Greg. Honestly speaking, I am not very familiar with how these environment variables work. This pr could be closed so that others may fix this issue. I am sorry about that.

@gziolo
Copy link
Member

gziolo commented Apr 12, 2019

@gziolo Hey Greg. Honestly speaking, I am not very familiar with how these environment variables work. This pr could be closed so that others may fix this issue. I am sorry about that.

Thanks for your response and starting this PR. Let's close it at suggested so someone else could give it a try :)

@gziolo gziolo closed this Apr 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Build Tooling Issues or PRs related to build tooling [Type] Developer Documentation Documentation for developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Abstract away and document advanced constants used in webpack config
4 participants