-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
- `--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). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Both |
||
|
||
### `check-engines` | ||
|
||
Checks if the current `node`, `npm` (or `yarn`) versions match the given [semantic version](https://semver.org/) ranges. If the given version is not satisfied, information about installing the needed version is printed and the program exits with an error code. It uses [check-node-version](https://www.npmjs.com/package/check-node-version) behind the scenes with the recommended configuration provided. You can specify your own ranges as described in [check-node-version docs](https://www.npmjs.com/package/check-node-version). | ||
|
@@ -170,7 +176,7 @@ This is how you execute the script with presented setup: | |
Launches the End-To-End (E2E) test runner. It uses [Jest](https://jestjs.io/) behind the scenes and you are able to utilize all of its [CLI options](https://jestjs.io/docs/en/cli.html). You can also run `./node_modules/.bin/wp-scripts test:e2e --help` or `npm run test:e2e:help` (as presented below) to view all of the available options. | ||
|
||
Writing tests can be done using Puppeteer API: | ||
|
||
> [Puppeteer](https://pptr.dev/) is a Node library which provides a high-level API to control Chrome or Chromium over the [DevTools Protocol](https://chromedevtools.github.io/devtools-protocol/). Puppeteer runs [headless](https://developers.google.com/web/updates/2017/04/headless-chrome) by default, but can be configured to run full (non-headless) Chrome or Chromium. | ||
|
||
_Example:_ | ||
|
@@ -196,7 +202,7 @@ We enforce that all tests run serially in the current process using [--runInBand | |
|
||
### `test-unit-js` | ||
|
||
_Alias_: `test-unit-jest` | ||
_Alias_: `test-unit-jest` | ||
|
||
Launches the unit test runner. It uses [Jest](https://jestjs.io/) behind the scenes and you are able to utilize all of its [CLI options](https://jestjs.io/docs/en/cli.html). You can also run `./node_modules/.bin/wp-scripts test-unit-js --help` or `npm run test:unit:help` (as presented below) to view all of the available options. By default, it uses the set of recommended options defined in [@wordpress/jest-preset-default](https://www.npmjs.com/package/@wordpress/jest-preset-default) npm package. You can override them with your own options as described in [Jest documentation](https://jestjs.io/docs/en/configuration). | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,11 +96,7 @@ const config = { | |
], | ||
}, | ||
plugins: [ | ||
// WP_BUNDLE_ANALYZER global variable enables utility that represents bundle content | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These inline comments should stay here. |
||
// as convenient interactive zoomable treemap. | ||
process.env.WP_BUNDLE_ANALYZER && new BundleAnalyzerPlugin(), | ||
// WP_LIVE_RELOAD_PORT global variable changes port on which live reload works | ||
// when running watch mode. | ||
! isProduction && new LiveReloadPlugin( { port: process.env.WP_LIVE_RELOAD_PORT || 35729 } ), | ||
].filter( Boolean ), | ||
stats: { | ||
|
@@ -109,8 +105,6 @@ const config = { | |
}; | ||
|
||
if ( ! isProduction ) { | ||
// WP_DEVTOOL global variable controls how source maps are generated. | ||
// See: https://webpack.js.org/configuration/devtool/#devtool. | ||
config.devtool = process.env.WP_DEVTOOL || 'source-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.
As I understand it, these are interpreted by the
wp scripts
script as environment variables, not as options flags.In other words, instead of:
I think the correct usage is...
Please correct me if I'm mistaken.
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.
Hi! Thanks for comments!
I am not sure which way is correct to use
--WP_BUNDLE_ANALYZER
. But for theWP_LIVE_RELOAD_PORT
, I have triednpm run build --WP_LIVE_RELOAD_PORT=12345
andnpm run build WP_LIVE_RELOAD_PORT=12345
. The first one works but the second one fails and the error message isAccording 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
andWP_DEVTOOL
.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.
@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.